Sharing R functionality with multiple users without exposing code [closed]

One option would be to expose your functions as services using something like Rserve. That would, however, require that you host the server running the code for your users.


When you use R code, there is imo no way to hide the code from the user. You can distribute binary packages of your package, but this still includes the R code in clear text. In addition, when the code is loaded into R, the user can look at the source of any function by typing it on the command line without parenthesis.

I'm not really sure why you want to hide the code. Maybe you could comment on that in your question to make things more clear for is. In addition, we might be able to come up with solutions other than hiding code which might answer your question. If hiding the code is is to keep implementation details from unexperienced users you could do the following.

  1. Create wrapper functions for the functions whose functionality want to make available to the user. Such a wrapper function can look something like:

    spam_wapper = function(a, b) {
       return(.spam(a = a, b = b))
    })
    
  2. Make all non-wrapper functions invisible to the user. They can still access them by explicitely stating the namespace of your package:

    pkgname::.spam
    

    but it is harder to get to the code, making it harder to find for unexperienced R programmers. But once they learn the trick, this won't help any longer.

If your reason is because you want to make money using your R code, hide your masterfully crafted R code (in which case I would defintely share it :)), or hide your code from any competition that might steal your idea. In that case the suggestion of @baptiste might work. But I guess it takes an aweful lot of work to rewrite your code in Fortran, C, or C++...I would say, just give them the source code...