Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Hlynsson
Created December 30, 2015 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hlynsson/8f1fda68075b7af54d50 to your computer and use it in GitHub Desktop.
Save Hlynsson/8f1fda68075b7af54d50 to your computer and use it in GitHub Desktop.
> rm(list=ls())
> someFunction <- function(x) { return(x*someVariable) }
> invisible(compiler::cmpfun(someFunction))
Note: no visible binding for global variable 'someVariable'
# Scoping can be an issue:
> someVariable <- 1
> invisible(compiler::cmpfun(someFunction))
# No more error because of lexical scope, to solve:
> poorMansLibrary <- new.env()
> poorMansLibrary$someFunction <- someFunction
> rm(list=setdiff(ls(),"poorMansLibrary"))
> for(fn in names(poorMansLibrary)){
out <- capture.output(invisible(compiler::cmpfun(poorMansLibrary[[fn]])))
if(length(out)>0) {
cat("Warnings from function: ",fn,"\n",paste(out,sep="\n"),"\n",sep="")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment