R/shim.R

Defines functions shimpkg

#function only used for development; it makes it easier to
#iterate on htmlwidgets without having to reinstall the package
#all the time. Just run it and load the package with load_all
#and then you can iterate on the javascript files quickly
#without reinstalling - reloading the package - the updated
#js files will be automatically reloaded.
shimpkg <- function(){

library(inline)

inc <- '
/* This is taken from envir.c in the R 2.15.1 source
https://github.com/SurajGupta/r-source/blob/master/src/main/envir.c
*/
#define FRAME_LOCK_MASK (1<<14)
#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) & FRAME_LOCK_MASK)
#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) & (~ FRAME_LOCK_MASK))
'

src <- '
if (TYPEOF(env) == NILSXP)
error("use of NULL environment is defunct");
if (TYPEOF(env) != ENVSXP)
error("not an environment");
UNLOCK_FRAME(env);
// Return TRUE if unlocked; FALSE otherwise
SEXP result = PROTECT( Rf_allocVector(LGLSXP, 1) );
LOGICAL(result)[0] = FRAME_IS_LOCKED(env) == 0;
UNPROTECT(1);
return result;
'

unlockEnvironment <- cfunction(signature(env = "environment"),
                               includes = inc,
                               body = src)

imports <- parent.env(asNamespace("htmlwidgets"))
unlockEnvironment(imports)
imports$system.file <- pkgload:::shim_system.file
}
riccardopinosio/selectR documentation built on May 14, 2019, 11:13 a.m.