Tudor Bodea
2008-Jul-17 15:57 UTC
[R] Hiding information about functions in newly developed packages
Dear UseRs: I intend to write a package to handle the basic operations a revenue management analyst has to deal with on a regular basis (e.g., demand untruncation, capacity allocation, pricing decisions, etc.). Following the directions posted by Peter Rossi (Making R Packages under Windows: A Tutorial, January 2006) I was able to build an interim package that currently consists of one simple function (e.g., fun). After the package is loaded and the function is invoked without any parameters (e.g., > fun) the body of the function is displayed on the screen underneath the function call. Since the user does not need to know the internal structure of the function, I am wondering if there is a way to hide this information. I have looked into some of the material that Paul Murrell and John Chambers among others posted but I have not really understood how to incorporate this information into the package building process. If you already experienced this issue and have some useful suggestions, I would really appreciate your taking the time to share them with me. For this project, I am using R2.7.1 on a Windows XP machine. Thank you. Tudor -- Tudor Dan Bodea Georgia Institute of Technology School of Civil and Environmental Engineering Web: http://www.prism.gatech.edu/~gtg757i
Peter Dalgaard
2008-Jul-17 16:55 UTC
[R] Hiding information about functions in newly developed packages
Tudor Bodea wrote:> Dear UseRs: > > I intend to write a package to handle the basic operations a revenue management > analyst has to deal with on a regular basis (e.g., demand untruncation, > capacity allocation, pricing decisions, etc.). Following the directions posted > by Peter Rossi (Making R Packages under Windows: A Tutorial, January 2006) I > was able to build an interim package that currently consists of one simple > function (e.g., fun). After the package is loaded and the function is invoked > without any parameters (e.g., > fun) the body of the function is displayed on > the screen underneath the function call. Since the user does not need to know > the internal structure of the function, I am wondering if there is a way to > hide this information. I have looked into some of the material that Paul > Murrell and John Chambers among others posted but I have not really understood > how to incorporate this information into the package building process. If you > already experienced this issue and have some useful suggestions, I would really > appreciate your taking the time to share them with me. For this project, I am > using R2.7.1 on a Windows XP machine. >A simple way is > print.invisible <- function(x) cat("Printing disabled\n") > class(ls) <- "invisible" > ls Printing disabled Of course, unclass(ls) still shows the definition, but I assume that the purpose was never to hide the progamming, just to avoid confusing users. Also of course, the same thing applies to all other functions in the system.... And, btw, "fun" is not "invoking the function without parameters", that would be "fun()". Typing the name is a request to see the function object. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Bert Gunter
2008-Jul-17 17:07 UTC
[R] Hiding information about functions in newly developed packages
You seems to be confused here. A function is "invoked" -- i.e. "called" -- via the expression fun(...) ## *Note the parentheses.* The function body is *not* printed. The expression fun ## note: no parentheses is not a call to the function. Rather, it is by default a call to the **print** method for the object, fun; when fun is a function, this prints the body of the function. One could change this by changing the S3 or S4 class of the object and defining the "print" or "show" method, respectively, to be something other than the standard "print the body of the function." I don't think this is necessarily a good idea, though. Incidentally, if the function is invoked without arguments ** that it needs and for which defaults have not been provide** then you'll get an error. Details on this can be found in ?print, ?print.default ?show and the relevant documentation on S3 and S4 methods (e.g. ?UseMethod ,?setClass, ?setMethod and various R docs). Perhaps before you write your package you would do well to do some more studying of the R language. Cheers, Bert Gunter Genentech -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Tudor Bodea Sent: Thursday, July 17, 2008 8:58 AM To: r-help at stat.math.ethz.ch Cc: Tudor Bodea Subject: [R] Hiding information about functions in newly developed packages Dear UseRs: I intend to write a package to handle the basic operations a revenue management analyst has to deal with on a regular basis (e.g., demand untruncation, capacity allocation, pricing decisions, etc.). Following the directions posted by Peter Rossi (Making R Packages under Windows: A Tutorial, January 2006) I was able to build an interim package that currently consists of one simple function (e.g., fun). After the package is loaded and the function is invoked without any parameters (e.g., > fun) the body of the function is displayed on the screen underneath the function call. Since the user does not need to know the internal structure of the function, I am wondering if there is a way to hide this information. I have looked into some of the material that Paul Murrell and John Chambers among others posted but I have not really understood how to incorporate this information into the package building process. If you already experienced this issue and have some useful suggestions, I would really appreciate your taking the time to share them with me. For this project, I am using R2.7.1 on a Windows XP machine. Thank you. Tudor -- Tudor Dan Bodea Georgia Institute of Technology School of Civil and Environmental Engineering Web: http://www.prism.gatech.edu/~gtg757i ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Marc Schwartz
2008-Jul-17 17:09 UTC
[R] Hiding information about functions in newly developed packages
on 07/17/2008 10:57 AM Tudor Bodea wrote:> Dear UseRs: > > I intend to write a package to handle the basic operations a revenue management > analyst has to deal with on a regular basis (e.g., demand untruncation, > capacity allocation, pricing decisions, etc.). Following the directions posted > by Peter Rossi (Making R Packages under Windows: A Tutorial, January 2006) I > was able to build an interim package that currently consists of one simple > function (e.g., fun). After the package is loaded and the function is invoked > without any parameters (e.g., > fun) the body of the function is displayed on > the screen underneath the function call. Since the user does not need to know > the internal structure of the function, I am wondering if there is a way to > hide this information. I have looked into some of the material that Paul > Murrell and John Chambers among others posted but I have not really understood > how to incorporate this information into the package building process. If you > already experienced this issue and have some useful suggestions, I would really > appreciate your taking the time to share them with me. For this project, I am > using R2.7.1 on a Windows XP machine. > > Thank you. > > TudorDo you want to have the function hidden in a 'namespace' or to actually attempt to keep the user from seeing your R source code at all? The latter is impossible in R. For the former, see that "Writing R Extensions" manual: http://cran.r-project.org/doc/manuals/R-exts.html#Package-name-spaces and the following article by Luke in R News: Luke Tierney. Name space management for R. R News, 3(1):2-6, June 2003 You could 'export' a wrapper function called fun(), but not export the main working internal function called fun.internal(). fun <- function(...) fun.internal(...) However, the body of the wrapper function would still be seen and if the user knows how to 'get' to functions within namespaces, they will be able see the full body of the internal function. HTH, Marc Schwartz
Maybe Matching Threads
- Insert raster image into an R graphic
- Place a string into the header/footer of a pdf file generated during a plot session
- R: Query an Access database based on a date attribute
- Append selectively to components of a list
- Query an Access database based on a date attribute