Re: [R] executing from .R source file in the src package

From: Duncan Murdoch <>
Date: Wed, 06 Apr 2011 08:05:03 -0400

On 11-04-06 2:13 AM, Larry wrote:
> Can I run R code straight from R src (.R) file instead of .rdb/.rdx? I of
> course tried simply unzipping tar.gz in the R_LIBS directory but R complains
> with "not a valid installed package".
> Real issue: I am very new to R and all, so this could be something basic.
> I'm trying to use ess-tracebug (Emacs front-end to trace/browser et al).
> It works great when I trace functions in .R files because browser outputs
> filename+line-number when it hits a breakpoint. i.e. something like this:
> debug at /home/lgd/test/R/test3.R#1: {
> It even moves the cursor as you step through the function. This is just
> lovely as I'm sure everyone knows. However, in case of a trace on function
> in a package (ie loaded from a .rdb/.rdx) there is no filename/linenum
> information probably because its not retained. i.e. it prints something
> like this:
> debugging in: train(net, P, target, error.criterium = "LMS", report = TRUE,
> Any way to work around this? Thanks for all insights.

I don't know ESS, but to get debug info in a package, you need to install the package with debug information included. By default source() includes it, installed packages don't.

Setting the environment variable


before running

R CMD INSTALL foo.tar.gz

will install the debug information. Then the browser, etc. will list filename and line number information. This is also necessary for setBreakpoint to work, but then you'll also probably need to say which environments to look in, e.g.

setBreakpoint("Sweave.R#70", env=environment(Sweave))

will set a breakpoint in whatever function is defined at line 70 of Sweave.R, as long as that function lives in the same environment as Sweave.

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 06 Apr 2011 - 12:06:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Apr 2011 - 12:10:27 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive