Hey everyone, I have made a package and wish to release it but before then I have a problem. I have a few functions in this package written in R that I wish to hide such that after installation, someone can use say the function >foo(parameters = "") but cannot do >foo. Typing foo should not show the source code or at least not all of it. Is there a way to do this ? I have searched the mailing list and used google, and have found something like "[R] Hiding internal package functions for the doc. pkg-internal.Rd" but this seems different since it seems that the keyword internal just hides the function from showing in the index and hides documentation, not the function itself. Can someone help? Thanks Gary
What you ask is impossible. For a function to be callable it has to be locatable and hence can be printed. One possibility is to have a namespace, and something like foo <- function(...) foo_internal(...) where foo is exported but foo_internal is not. Then foo_internal is hidden from casual inspection, but it can be listed by cognescenti. Why do you want to do this? Anyhone can read the source code of your package, and any function which can be called can be deparsed, possibly after jumping through a few hoops. On Sat, 30 Jul 2005, Gary Wong wrote:> Hey everyone, > > I have made a package and wish to release it but > before then I have a problem. I have a few functions > in this package written in R that I wish to hide such > that after installation, someone can use say the > function >foo(parameters = "") but cannot do >foo. > Typing foo should not show the source code or at least > not all of it. Is there a way to do this ? I have > searched the mailing list and used google, and have > found something like "[R] Hiding internal package > functions for the doc. pkg-internal.Rd" but this seems > different since it seems that the keyword internal > just hides the function from showing in the index and > hides documentation, not the function itself. Can > someone help? Thanks-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
You could set the source attribute like this: R> f <- function(x) x+1 R> # displays the word hidden instead of showing the source R> attr(f, "source") <- "hidden" R> f hidden R> f(10) # still works as a function properly [1] 11 Of course, someone knowledgable could change the source attribute back but this would prevent casual inspection. On 7/30/05, Gary Wong <wongg62 at pacbell.net> wrote:> Hey everyone, > > I have made a package and wish to release it but > before then I have a problem. I have a few functions > in this package written in R that I wish to hide such > that after installation, someone can use say the > function >foo(parameters = "") but cannot do >foo. > Typing foo should not show the source code or at least > not all of it. Is there a way to do this ? I have > searched the mailing list and used google, and have > found something like "[R] Hiding internal package > functions for the doc. pkg-internal.Rd" but this seems > different since it seems that the keyword internal > just hides the function from showing in the index and > hides documentation, not the function itself. Can > someone help? Thanks > > Gary > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
I always thought that ability to see and study the code of every package, was a great thing about R and other "open source" environments. So I hope there are no good ways of hiding the code of packages. Jarek ====================================================\====== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation <\__,| (703) 676-4192 "> \ Jaroslaw.W.Tuszynski at saic.com ` \ -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Gary Wong Sent: Saturday, July 30, 2005 4:21 AM To: r-help at stat.math.ethz.ch Subject: [R] How to hiding code for a package Hey everyone, I have made a package and wish to release it but before then I have a problem. I have a few functions in this package written in R that I wish to hide such that after installation, someone can use say the function>foo(parameters = "") but cannot do >foo.Typing foo should not show the source code or at least not all of it. Is there a way to do this ? I have searched the mailing list and used google, and have found something like "[R] Hiding internal package functions for the doc. pkg-internal.Rd" but this seems different since it seems that the keyword internal just hides the function from showing in the index and hides documentation, not the function itself. Can someone help? Thanks Gary ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
There's something else you could try - since you can't hide the code, obfuscate it. Hide the real thing in a large pile of useless, complicated, awfully formatted code that would stop anyone except the most desperate (including yourself, after a couple of weeks/months) from trying to understand it. The best solution would be to compile the code, but R is not there yet.> -----Original Message----- > From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk] > Sent: Saturday, July 30, 2005 5:35 AM > To: Gary Wong > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] How to hiding code for a package > > > What you ask is impossible. For a function to be callable it > has to be > locatable and hence can be printed. > > One possibility is to have a namespace, and something like > > foo <- function(...) foo_internal(...) > > where foo is exported but foo_internal is not. Then foo_internal is > hidden from casual inspection, but it can be listed by cognescenti. > > Why do you want to do this? Anyhone can read the source code of your > package, and any function which can be called can be > deparsed, possibly > after jumping through a few hoops. > > On Sat, 30 Jul 2005, Gary Wong wrote: > > > Hey everyone, > > > > I have made a package and wish to release it but > > before then I have a problem. I have a few functions > > in this package written in R that I wish to hide such > > that after installation, someone can use say the > > function >foo(parameters = "") but cannot do >foo. > > Typing foo should not show the source code or at least > > not all of it. Is there a way to do this ? I have > > searched the mailing list and used google, and have > > found something like "[R] Hiding internal package > > functions for the doc. pkg-internal.Rd" but this seems > > different since it seems that the keyword internal > > just hides the function from showing in the index and > > hides documentation, not the function itself. Can > > someone help? Thanks > > -- > Brian D. Ripley, ripley at stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UK Fax: +44 1865 272595 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >