views:

105

answers:

3

I am developing a package in R

When I am debugging a particular function or set of functions, what is the best way to test the function?

Do I have to either use source('function.R') or R CMD build each time I want to check my changes?

(extra credit for associated emacs ess key-bindings)

+3  A: 

Take a look at ?insertSource, which is a new function in R 2.12.0, plus the other functions in the See Also section of that help page. Also, check out ?assignInNamespace if your package has a Namespace.

The above presumes you are talking about updating and debugging R sources, not compiled code.

I generally have used the source() route to load new versions of functions I am improving/debugging, alongside the usual R debugging tools. But I haven't got Namespaces in my packages as yet. My fingers have gotten quite used to the C-c C-l keybinding in emacs+ess for sourcing a buffer over the years.

Gavin Simpson
Thanks for your answer: C-c C-l is helpful, but just to note for others, when using this on a server (in ess-remote mode), the file path starts with ~/pkg/R/fn.R rather than /server:pkg/R/fn.R even though when I write the file, it is to the /server:.. locationif I dont use the server location, I get the error: cannot open file '/ssh:server/home/usr/pkg/R/function.R' have you noticed this?
David
@David: sorry, my emacs+ess fu is weak. I've never used it in the manner you are describing. (I presume you aren't editing the local version and expecting ESS to somehow know where the file is on the server?) Suggest you ask the above as a new question here, where it will get more eyes than a Q about R package development.
Gavin Simpson
+1  A: 

See also http://github.com/hadley/devtools/ which provides some tools to make this task easier.

hadley