[Rd] how to make a true binary package?

Duncan Murdoch murdoch.duncan at gmail.com
Wed Oct 12 22:43:19 CEST 2011

On 12/10/2011 3:57 PM, Greg Snow wrote:
> If you want to hide some code from accidental or casual sight then I have had some success with adding something like this to the .R file for a package (the petals function in TeachingDemos in this case):
> .onAttach<- function(...) {
>      petals<- petals
>      attr(petals,'source')<- "Don't Cheat!"
>      assign('petals',petals,'package:TeachingDemos')
> }
> Though that would only slow an experienced R programmer down by maybe 10 seconds if they really wanted to see the code, it might take an intermediate level R programmer a whole minute to figure out how to work around this.  But it would prevent an honest user that knew of a license or agreement to not look at the code from accidentally seeing what they agreed not to.

You should be aware that this will no longer work in R 2.14.0, which 
finally drops the "source" attribute.  This would achieve a similar effect:

srcfile <- srcfilecopy("", "Don't cheat")
srcref <- srcref(srcfile, c(1,1,1,12))
attr(petals, "srcref") <- srcref

Duncan Murdoch

> You could also include something in the code that checked the attribute and stopped working if it was changed or somehow notified you of the change.  Combining this with the license agreements as others have said might give you additional recourse.
> You can see the petals.R file in the TeachingDemos package on R-forge for another example of obfuscating (bleaching) a key piece of code.  Combining the 2 might slow down an expert by a whole 30 seconds, but at least they would not be able to claim that they accidentally saw the code.
> Whether this violates the spirit of R licensing or not is another issue.

More information about the R-devel mailing list