Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making R package work in both Windows and Linux

Tags:

package

r

I have written a very basic package in R. In fact, I followed this tutorial for 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")

like image 334
poundifdef Avatar asked Nov 06 '09 03:11

poundifdef


People also ask

What happens if you install a package twice in R?

It shouldn't be an issue unless you install a package as an admin user, and again as a normal user. Then you will have a version in two different locations on your system. That could lead to issues when upgrading, or confusion as to which version is loaded.

Do I need to install R packages every time?

You only need to install packages the first time you use R (or after updating to a new version). **R Tip:** You can just type this into the command line of R to install each package. Once a package is installed, you don't have to install it again while using the version of R!

How do you install all R packages at once?

Alternatively, you can install R packages from the menu. In RStudio go to Tools → Install Packages and in the Install from option select Repository (CRAN) and then specify the packages you want. In classic R IDE go to Packages → Install package(s) , select a mirror and install the package.


2 Answers

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.

like image 98
Dirk Eddelbuettel Avatar answered Oct 14 '22 00:10

Dirk Eddelbuettel


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.

like image 26
Rob Hyndman Avatar answered Oct 13 '22 23:10

Rob Hyndman