Skip to content

Verbose output from R CMD check

8 messages · Simon Urbanek, dpleydell, Peter Dalgaard

#
I've been developing a package called foobar for a couple of years now. 
It has evolved through various versions, but has always contained 
compiled C code. Recently, R CMD check has started generating the 
following message

[START QUOTE]

R CMD check foobar_1.7.5.tar.gz
* using log directory ?/home/david/foobar/package/foobar.Rcheck?
* using R version 2.15.2 (2012-10-26)
* using platform: x86_64-unknown-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ?foobar/DESCRIPTION? ... OK
[LOTS OF '...OK' CHECK REPORTS REMOVED FOR BREVITY]
* checking compiled code ... NOTE
File ?/home/david/foobar/package/foobar.Rcheck/foobar/libs/foobar.so?:
   Found ?putchar?, possibly from ?putchar? (C)
     Object: ?foobar.o?
   Found ?puts?, possibly from ?printf? (C), ?puts? (C)
     Object: ?foobar.o?

Compiled code should not call functions which might terminate R nor 
write to stdout/stderr instead of to the console.

See ?Writing portable packages? in the ?Writing R Extensions? manual.
* checking examples ... OK
* checking PDF version of manual ... OK

NOTE: There was 1 note.
See ?/home/david/foobar/package/foobar.Rcheck/00check.log? for details.

[END QUOTE]

This message is recent, but appears even when I re-compile and check old 
versions of the package which previously passed the check without any 
such warning messages.

My understanding is that since R 2.15.0 R CMD check has undergone 
numerous modifications, and as a result it is now identifying a 
"problem" that wasn't being identified previously. I'm currently running 
R 2.15.2.

Identifying the source of the message is a non-trivial problem because 
there are a large number of calls to printf and fprintf etc in several 
thousands of lines of code spread over many different *.c files.

So my question... is there a way to obtain a more verbose output that 
could point me to the lines of code that generate the message? Without 
this information debugging is rendered unnecessarily hard, time 
consuming and frustrating.

many thanks
David
#
On Apr 23, 2013, at 10:51 AM, dpleydell wrote:

            
There should be none, so apparently you have broken the rules quite a lot ;). This is not a new rule, R just got better at identifying the transgressions. Number of lines in your code is quite irrelevant - that's why there is grep and the search function in editors.
It's not "unnecessarily hard" - it fact it's much easier to find this out from the sources than the compiled code which is how R has to identify it which makes it impossible to track the source (because it could have been from a static library, for example).

Cheers,
Simon
#
On Apr 23, 2013, at 12:43 PM, dpleydell wrote:

            
We're not talking life and death here ;) - yes, frustrated users because of messed up output is the main danger here. Also the behavior changes by GUI and platform, so throw in inconsistency charge as well.

To be precise, there are two issues: a) the output on stdout/stderr is not necessarily visible (e.g. the Windows GUI discards it) and it is separate from the console (e.g. sink() doesn't work on it). More importantly b) it messes up the use of R in streaming, i.e. uses where you are processing input on stdin and streaming output on stdout -- it will break the output. This is most frustrating because the user has no way to control this behavior other than deleting the offending package.
fprintf() is ok as long as you don't use it with stdout/stderr. You can use it for files, no problem there.
Typically, I/O is buffered, so the file is not necessarily updated after you use fprintf(). By default, it will get updated only after the output buffer has been filled. You can use fflush() to flush the output buffer to disk immediately (alternatively you can mark the stream as unbuffered).
If MCMCout is a file, the above is fine.
Yes, sure.

Cheers,
Simon
#
Many thanks for these comments Simon, that really helps me a lot!

warm regards
David
On 23/04/13 19:30, Simon Urbanek wrote:

  
    
1 day later
1 day later
#
On Apr 25, 2013, at 22:01 , dpleydell wrote:

            
Longshot: 

grep '[^Rf]printf' *.c

might turn up cases not found by the pipeline above.

Apart from that, trying out the nm command on your .o and .so files could be enlightening.  If push comes to shove, you might compile to assembler code (gcc -S, as far as I remember) and look for the offending puts symbol in the output.
2 days later
#
Peter's longshot hit the bull's eye, this was the offending line

foobar.c:  if (*smoothOrStochastic==0) Rprintf("0\n"); else (printf("1\n"));

So I clearly need to brush up a little on regular expressions. The 
mistake is the scripting was that I used this

find . -maxdepth 1 -type f -name '*.c' -exec sed -i 's\printf\Rprintf\'{} \;
find . -maxdepth 1 -type f -name '*.c' -exec sed -i 's\fRprintf\fprintf\' {} \;

and not this

find . -maxdepth 1 -type f -name '*.c' -exec sed -i 's\printf\Rprintf\g'{} \;
find . -maxdepth 1 -type f -name '*.c' -exec sed -i 's\fRprintf\fprintf\g' {} \;

Many thanks Simon, Peter and Martin for your suggestions, R CMD check 
now runs clean :-)
David