Making R package work in both Windows and Linux
I have written a very basic package in R. In fact, I followed this tutorial f开发者_运维问答or creating a basic package.
My package works just fine in linux. eg:
> install.packages("linmod", repos=NULL) Warning in install.packages("linmod", repos = NULL) : argument 'lib' is missing: using '/home/jpgoel/R/i486-pc-linux-gnu-library/2.9' * Installing *source* package ‘linmod’ ... ** R ** data ** preparing package for lazy loading ** help *** installing help indices >>> Building/Updating help pages for package 'linmod' Formats: text html latex example ** building package indices ... * DONE (linmod) > library(linmod) > data(mod1) > mod1 Call: linmod.default(x = x, y = y) Coefficients: Const Bwt -0.3566624 4.0340627
Now, I took my "linmod" folder, copied it to Windows XP, and tried the following:
> install.packages("C:\\Documents\ and\ Settings\\foo\\Desktop\\linmod",repos=NULL) Error in gzfile(file, "r") : cannot open the connection In addition: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In gzfile(file, "r") : cannot open compressed file 'linmod/DESCRIPTION', probable reason 'No such file or directory' >
Okay. So then I took that folder and placed it into a .zip file. Then I went to Packages -> Install package(s) from local zip files... and selected my package.
> utils:::menuInstallLocal() updating HTML package descriptions > library(linmod) Error in library(linmod) : 'linmod' is not a valid installed package
I'm stumped. My package doesn't have any native code (eg, no extensions written in C.)
Feel free to download the .zip from here (the link to download is all the way at the bottom, "Save file to your PC")
Consider using the excellent CRAN Win-Builder service to turn your R package sources into an installable zip file for Windows.
You simply upload by ftp, and shortly thereafter get notice about your package.
You can't just zip up the directory from linux. You need to build specifically for Windows. I've put some instructions here. However, if you are developing on some other platform first, then Dirk's solution is simpler.
If the package is rather simple, the following function works for me on Windows for a package "MY_PACKAGE_1.0.tar.gz" generated with R (OS: Ubuntu with the command R CMD build MY_PACKAGE
)
install.packages("MY_PACKAGE_1.0.tar.gz", repos=NULL, type="source")
The option type="source"
is necessary, otherwise it does not work.
精彩评论