[R] how to hide code of any function

Duncan Murdoch murdoch.duncan at gmail.com
Thu Mar 15 16:23:03 CET 2012


On 15/03/2012 8:53 AM, mrzung wrote:
> hi
>
> I'm making some program and it need to be hidden.
>
> it's not commercial purpose but it is educational,
>
> so i do want to hide the code of function.
>
> for example,
>
> if i made following function:
>
> a<-function(x){
> y<-x^2
> print(y)
> }
>
> i do not want someone to type "a" and take the code of the function.
>
> is there anyone who can help me?

R has no explicit support for that.  If your function is written in R 
code, it won't be hard to find the source.  So you could write your 
function in C and not distribute the source (assuming all of your users 
are on one platform), or you could write obscurely so that it's not 
obvious what you are doing, e.g.

a <- function(x) {
   eval(parse(text=somestring))
}

environment(a) <- new.env()
environment(a)$somestring <- "y <- x^2; print(y)"

However, this won't slow down anyone who knows about the debug() function.

Duncan Murdoch



More information about the R-help mailing list