0

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.

Ben McCann
  • 18,548
  • 25
  • 83
  • 101

5 Answers5

4

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
  • 360,940
  • 56
  • 644
  • 725
  • 2
    @Ben McCann: He did not yust tell you to RTFM, he pointed you to the right one... – nico Aug 04 '10 at 07:17
  • 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 Aug 04 '10 at 17:58
  • 6
    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 Aug 04 '10 at 18:13
2

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
  • 59,675
  • 58
  • 202
  • 294
0

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
  • 18,402
  • 3
  • 47
  • 45
0

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
  • 2,712
  • 2
  • 20
  • 25
  • 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 Aug 04 '10 at 18:29
  • 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 Aug 05 '10 at 20:11
-2

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
  • 18,548
  • 25
  • 83
  • 101
  • 4
    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 Aug 04 '10 at 13:37