4

I have code that will read in and process data that I would like to allow multiple users to use, but I do not want to allow them to see the code.

Is there a way to do this using R or RStudio?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Rick Gittins
  • 1,138
  • 1
  • 8
  • 24
  • 8
    Having a repository is entirely orthogonal to whether users can see code or not. This is the second time you asked this question, and you are still asking it in a poorly worded manner. If your real question is: "How do I hide code from a user" then the answer is probably "only with some difficulty". – Dirk Eddelbuettel Apr 20 '12 at 19:57
  • It's interesting how someone who is trying to ask a question gets bashed by the "experts". I don't seem to care about trying to build up a reputation on this site. – Rick Gittins Apr 20 '12 at 20:15
  • 5
    Many of us contribute open source code. We may not be the best group to ask about hiding code... – Dirk Eddelbuettel Apr 20 '12 at 20:35
  • 5
    You're probably getting "bashed" because you do not demonstrate that you have actually expended any effort to solve this problem, other than asking "experts" to do it for you. – Joshua Ulrich Apr 20 '12 at 20:37
  • 3
    See e.g. http://stackoverflow.com/questions/4707276/encrypting-r-script-under-ms-windows . There are two reasons for the snarky comments: (1) R developers are not all that friendly to code-hiding attempts (although as explained e.g. at the linked question, there are certainly legitimate reasons) (2) you're not to blame for ignorance, but "code repository" is not the right (=standard in the community) term for what you want to do. I'm going to go ahead and edit your question, feel free to rollback/re-edit it yourself. It might also help if you gave more context ... – Ben Bolker Apr 20 '12 at 21:47
  • Both `code-protection` and `source-code-protection` tags exist ... I don't have the appropriate rep to suggest that they are synonyms, but perhaps someone else can ... – Ben Bolker Apr 20 '12 at 21:54
  • 8
    I've never thought of this in any depth, but could we imagine that the R code be embedded in C/C++ code via `rinside` perhaps, compiled into a shared library, and called from R after deleting/hiding the original source? – baptiste Apr 20 '12 at 22:33
  • In addition to the suggestions in the other question, linked to by @BenBolker and the server suggestions below, you can also try compiling the code. Frankly, I most prefer server side management, because I can then more easily update a package without having to manage distribution to users, along with tons of other benefits. Basically, SaaS has a lot of upside beyond just IP considerations... – Iterator Apr 21 '12 at 16:09

2 Answers2

9

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.

Jeff Allen
  • 17,277
  • 8
  • 49
  • 70
  • +1 Agreed. RStudio Server also works for this solution, along with many other packages that host the code server-side. – Iterator Apr 21 '12 at 16:07
  • 5
    But using RStudio Server you do not hide the code. The R session is running remotely, but a user can still see all the code that is used. – Paul Hiemstra Apr 24 '12 at 08:51
3

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...

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149