1

I want to put the following function in my .Rprofile to make installation of bioconductor packages easier:

install.bioconductor <- function(...) {
  source("http://bioconductor.org/biocLite.R")
  biocLite(...)
}

But when I load a new R session, this function is now listed when I call ls. Is there a way of masking the function from being shown?

Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64

1 Answers1

3

You can put it in its own environment and attach that environment to the search path.

myFUNs <- new.env()
myFUNs$install.bioconductor <- function(...) {
  source("http://bioconductor.org/biocLite.R")
  biocLite(...)
}
attach(myFUNs) # attach to the search path
rm(myFUNs)     # remove from .GlobalEnv

# it is still accessible via 
# install.bioconductor(...)

Then it be accessible, but will not show up in ls(). (You can see what is attached to the search path with search(), and you can see what is in myFUNs with ls(myFUNs))

Alternatively, as @JoshuaO'Brien mentioned in a comment you can keep it in the .GlobalEnv but add a dot to the beginning of the name (i.e. name it .install.bioconductor) so that it will be "hidden" such that it won't show up with ls(), but will show up with ls(all.names=TRUE).

Community
  • 1
  • 1
GSee
  • 48,880
  • 13
  • 125
  • 145
  • Is there a way to mask `myFUNs` from `ls` as well? Both solutions are good, but not exactly what I'm looking for. I think I need to sit down and write a package to hold my utility functions. – Scott Ritchie Jul 18 '13 at 17:43
  • 1
    @Manetheran, after you've `attach`ed it to the search path, you can just remove it from your `.GlobalEnv` with `rm(myFUNs)` – GSee Jul 18 '13 at 17:46