Re: [Rd] Tips for debugging: R CMD check examples

2010-06-30 Thread Tobias Verbeke

On 06/29/2010 11:56 PM, Hadley Wickham wrote:


Does anyone have any suggestions for debugging the execution of
examples by R CMD check?  The examples work fine when I run them from
a live R prompt, but I get errors when they are run by R CMD check.


Not a real tip, but when it occurs I immediately
check for namespace issues (which often turn out
to be the origin). Things I do are

- verify all packages involved have namespaces;
- load all packages (i.e. put explicitly on the
  search path) to detect masking issues;
- check all imports and exports and if relevant
  turn package imports into individual function
  imports to have a more fine-grained view.

Agreed this is a very indirect way, but at times
faster than trying to interpret the error message.

Best,
Tobias

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tips for debugging: R CMD check examples

2010-06-30 Thread Deepayan Sarkar
On Wed, Jun 30, 2010 at 3:26 AM, Hadley Wickham had...@rice.edu wrote:
 Hi all,

 Does anyone have any suggestions for debugging the execution of
 examples by R CMD check?  The examples work fine when I run them from
 a live R prompt, but I get errors when they are run by R CMD check.

'R CMD check pkg' will produce a pkg.Rcheck/pkg-Ex.R file that
collects the examples into a single file (and also does other things).
You could try running that file interactively to see if the error is
reproduced.

-Deepayan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tips for debugging: R CMD check examples

2010-06-30 Thread Spencer Graves

Hi, Hadley:


  1.  Is your memory clear when you run the examples successfully?  
I.e., start with rm(list=objects()), then try the examples that work 
interactively but fail in R CMD check.



  2.  Also, does R CMD check give any warnings, e.g., undefined 
global, in addition to the error message?  If yes, fixing those might 
also fix the error message.



  The suggestions of Deepayan and Sarker are excellent, but the two 
things I suggests are more targeted and might work, so I'd try them first.



  Hope this helps.
  Spencer


On 6/30/2010 1:05 AM, Deepayan Sarkar wrote:

On Wed, Jun 30, 2010 at 3:26 AM, Hadley Wickhamhad...@rice.edu  wrote:
   

Hi all,

Does anyone have any suggestions for debugging the execution of
examples by R CMD check?  The examples work fine when I run them from
a live R prompt, but I get errors when they are run by R CMD check.
 

'R CMD check pkg' will produce a pkg.Rcheck/pkg-Ex.R file that
collects the examples into a single file (and also does other things).
You could try running that file interactively to see if the error is
reproduced.

-Deepayan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
   



--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tips for debugging: R CMD check examples

2010-06-30 Thread hadley wickham
 R CMD check produces a foo-Ex.R file where foo is the package name. You
 could start by sourcing that file in R --vanilla and see where it fails
 and also use standard debugging tools in R from there (i.e. drop into a
 debugger on error).

I knew about the foo-Ex.R file, but unfortunately running that
produced no errors. I ended up resorting to inserting print statements
every few lines to narrow down the exact location of the problem,
which revealed that my code assumed options(keep.source = TRUE) but
during R CMD check, options(keep.source = FALSE).

Hopefully this type of problem will be easier to sort out with the new
pure R R CMD check in 2.11.

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tips for debugging: R CMD check examples

2010-06-30 Thread Hadley Wickham
 Not a real tip, but when it occurs I immediately
 check for namespace issues (which often turn out
 to be the origin). Things I do are

I agree that namespace issues are often a problem, and are never easy
to diagnose - I often find that I've forgotten to export a method
definition so other code silently falls back on the default method and
leads to head scratching bugs.

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tips for debugging: R CMD check examples

2010-06-30 Thread Prof Brian Ripley

On Wed, 30 Jun 2010, hadley wickham wrote:


R CMD check produces a foo-Ex.R file where foo is the package name. You
could start by sourcing that file in R --vanilla and see where it fails
and also use standard debugging tools in R from there (i.e. drop into a
debugger on error).


I knew about the foo-Ex.R file, but unfortunately running that
produced no errors.


How did you 'run' it?   I suspect you source()d it, not at all the 
same thing.  I have yet to encounter a problem which


R --vanilla  foo-Ex.R

or perhaps

env LANGUAGE=en R --vanilla --encoding=latin1  foo-Ex.R

did not reproduce.


I ended up resorting to inserting print statements
every few lines to narrow down the exact location of the problem,
which revealed that my code assumed options(keep.source = TRUE) but
during R CMD check, options(keep.source = FALSE).


Rather, the default (along with many others) differs in interactive 
use and batch running.   If you had used a command like those a few 
lines about you would have had 'keep.source = FALSE' set.



Hopefully this type of problem will be easier to sort out with the new
pure R R CMD check in 2.11.


Maybe (if you meant the one in R-devel, 2.12.0-to-be). But the 
examples are run in a sub-process just as before, so your very rare 
mis-assumption still needs an understanding of how R code is run.




Hadley


--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Tips for debugging: R CMD check examples

2010-06-30 Thread hadley wickham
 How did you 'run' it?   I suspect you source()d it, not at all the same
 thing.  I have yet to encounter a problem which

 R --vanilla  foo-Ex.R

 or perhaps

 env LANGUAGE=en R --vanilla --encoding=latin1  foo-Ex.R

 did not reproduce.

Thanks, that was exactly what I was looking for.  I hadn't tried
running it in batch mode.

 Rather, the default (along with many others) differs in interactive use and
 batch running.   If you had used a command like those a few lines about you
 would have had 'keep.source = FALSE' set.

I think the root of the problem is the way that source is written - it
uses a global option in an internal branch, which is difficult to
notice unless you read the source code. It seems like a good principle
that global options should only affect program behaviour by modifying
the function arguments.

 Hopefully this type of problem will be easier to sort out with the new
 pure R R CMD check in 2.11.

 Maybe (if you meant the one in R-devel, 2.12.0-to-be). But the examples are
 run in a sub-process just as before, so your very rare mis-assumption still
 needs an understanding of how R code is run.

Ooops, yes, I meant 2.12.0-to-be.  I was thinking it would make the
problem easier for me to understand because I'm more inclined to read
R code rather than perl code.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Tips for debugging: R CMD check examples

2010-06-29 Thread Hadley Wickham
Hi all,

Does anyone have any suggestions for debugging the execution of
examples by R CMD check?  The examples work fine when I run them from
a live R prompt, but I get errors when they are run by R CMD check.

Thanks,

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel