I'm a beginner with R (2 weeks at it), and am having a problem with something that should be simple: creating a package.
Just to get up and running, I've created a simple function:
square <- function(number)
{
answer <- number * number
return(answer)
}
Then I've set my working directory to where all of my other R packages are installed
setwd("/usr/local/lib/R/site-library")
Then I create a package
package.skeleton(list = c("square"), name = "sbpackage01")
All files show up as expected in the new 'sbpackage01' directory, but when I open RCommander and try to use the package with
library(sbpackage01)
it tells me
'sbpackage01' is not a valid installed package
Any suggestions on what I'm missing? The next step in the tutorials I've seen is to compress then install it, but isn't the package installed by just doing 'package.skeleton...'?
Thanks for your help!
something that should be simple: creating a package.
Haha. Well, no, creating a package in R isn’t quite simple (compared to module systems in other languages). You’re on the right track but before you can use your package you need to install it (or use devtools
to install and load it dynamically).
The command package.skeleton
actually creates a file Read-and-delete-me
in your package directory which contains a short explanation of how to do this. Very briefly, you need to run the following command on the command line, from the parent directory of your package directory:
R CMD build packagename
R CMD INSTALL packagename
This is just a very brief explanation. Be sure to read one of the more detailed explanations, such as Friedrich Leisch’s Creating R Packages: A Tutorial [PDF].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With