tags:

views:

115

answers:

5

I'd like to fix a package, but can't figure out how to edit it. I can download the source from R-Forge as a .tar.gz and unzip it. There is an "R" directory with the source and also a "tests" directory.

How do I include the sources in my own project to test my edits?

How do I run the tests? The tests each start with "library(blotter)". How do I make that load the library from the sources I've downloaded.

A: 

What I have done is the following (IIRC) remove the old package remove.packages. Re zip your new package to a tar.gz file again (with your changed sources). Install the new package with install.packages with pkg = path to your zipped library, and repos=NULL.

deinst
wow. that's an incredible pain. is there anyway to do it without having to continually zip my source code after each change I make?
Ben McCann
You've go a computer, automate it.
deinst
+2  A: 

The recommended process is described in some detail in the manual 'Writing R Extensions' that came with your R installation.

There are also numerous tutorials all over the web.

Dirk Eddelbuettel
@Ben McCann: He did not yust tell you to RTFM, he pointed you to the right one...
nico
Hehe, I'll try to be less blunt next time. I do appreciate the help. The thing that's so great about stack overflow is that you can get specific answers to quick questions. I do appreciate pointers to specific sections of the manual with perhaps an excerpt included :o) Less helpful is oh it's somewhere in those 141 pages.
Ben McCann
If you appreciate the help, up-vote the answer. And rest assured you will have to read more than 141 pages if you want to put R to good use. Much more.
Dirk Eddelbuettel
A: 

I found that I could load all the sources to save me from the ridiculous repackaging by doing:

for (file in dir("../R", pattern="*.R", full.names=TRUE)) {
  source(file)
}
Ben McCann
A similar function is included in the examples of `?source`... but I'm really not helping since you know how to read the manual, right?
Joshua Ulrich
+1  A: 

No need to re-zip the source. Just load the package again from the source on your drive:

install.packages(/path/to/package, repos = NULL, type="source")

your method of doing the for loop to loop across R files will work in some situations but in others it may not. For example, if there is compiled non R code then looping across the *.R files may not work properly. So it's generally better to just install.packages() again.

BTW, if you clone a version control repo to your hard drive you generally don't get the zip file. So the same method is used to install.

JD Long
A: 

When I'm doing testing on a package, I use a little bash script that looks like this:

#!/bin/bash
#build the package from source
R CMD build ../pkgdirectory/
#remove the old version and install the new one
R CMD REMOVE pkgname
R CMD INSTALL pkgname_0.7.tar.gz

Replace package name with the appropriate names. Save it as "make" and then run it whenever you finish a major edit. Then your testing scripts can use library(pkgname) just like normal.

chrisamiller
You can skip the remove step; it is done for you the install that follows. You could however add a `R CMD check` step, based on the tarball you created.
Dirk Eddelbuettel
Thanks for the remove tip. Yeah, I often include the check, especially in the early stages of putting a package together, but when I'm only tweaking code, I skip that step since it takes a while.
chrisamiller