4

Is it possible to convert source code (mypackage.tar.gz) to window installation (mypackage.zip) in R at home ? How can I do it ?

I could unzip tar.gz using 7-Zip. When I tried to recompile the following is error message:

Loading required package: mypackage Failed with error: ‘‘mypackage’ is not a valid installed package’

2 Answers 2

9

No, you need to install Rtools and compile the binary package ending in .zip from the source package ending in .tar.gz. And the package / building "compiling" step is needed even for packages containing only R code.

Try one of the many tutorials on the web about package building on Windows.

Alternatively, use the awesome win-builder site to create the package for you.

2

I develop my R packages on Linux machines - if you do too, this is what I do and it may help you.

To make the .zip for R, I basically 'install' it to a temporary directory and zip it up. That .zip file can be used on windows.

# make the package:
R CMD build my_package

# make tmp directory
mkdir tmp

# install the package to temp directory
R CMD INSTALL -l tmp my_package.tar.gz

# zip it up
cd tmp
zip -r my_package.zip my_package

# move your zip file back out and delete tmp directory
mv my_package.zip ../
cd ../
rm -rf tmp

I put this all into a makefile for ease so that I can type (e.g.) make doc to generate documentation (since I use roxygen2), make package to do the R CMD build, make zip to convert the .tar.gz into a .zip etc.

3
  • This method only works if there is C/C++/Fortran code to be compiled so it won't be working on mclust, and is generally discouraged as can be seen by threads on the R lists. Mar 20, 2012 at 12:35
  • Oh, I forgot to mention I have only R code (I imagine it wouldn't work with any compiled code?). When I faced the same dilemma as the OP a few months ago, I looked as hard as I could on the R mailing list archive and could only find one relevant thread where the guy did the R CMD INSTALL followed by the zip, which is why I've adopted this into my workflow. I'm always happy to improve this though and will now look into Rtools, except my requirements are to build the Windows .zip under Linux, whereas Rtools seems to be building under Windows? Mar 20, 2012 at 23:18
  • If you live with your code being out of your hands, nothing beats win-builder :) Mar 20, 2012 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.