[Rd] Small nit in Sweave

2011-11-15 Thread Terry Therneau
Two small Sweave issues.

1. I had the following line in my code
   echo=FALSE, results=hide

resulting in the message
Error in match.arg(options$results, c(verbatim, tex, hide)) : 
  'arg' should be one of “verbatim”, “tex”, “hide”

  I puzzled on this a bit since my argument exactly matched the message,
until I thought of trying it without the quotes.

2. Where should I have reported this?  Sweave is not on CRAN so I
couldn't find the maintainer email there.  Perhaps I'm missing something
obvious though

Terry T.

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


Re: [Rd] Small nit in Sweave

2011-11-15 Thread Marc Schwartz
On Nov 15, 2011, at 1:10 PM, Terry Therneau wrote:

 Two small Sweave issues.
 
 1. I had the following line in my code
   echo=FALSE, results=hide
 
 resulting in the message
 Error in match.arg(options$results, c(verbatim, tex, hide)) : 
  'arg' should be one of “verbatim”, “tex”, “hide”
 
  I puzzled on this a bit since my argument exactly matched the message,
 until I thought of trying it without the quotes.
 
 2. Where should I have reported this?  Sweave is not on CRAN so I
 couldn't find the maintainer email there.  Perhaps I'm missing something
 obvious though
 
 Terry T.


Interesting. I never thought of using the 'results' options as quoted character 
vectors, even though in ?RweaveLatex, the description for the 'results' options 
indicates:

character string (verbatim). If verbatim, the output of R commands is 
included in the verbatim-like Soutput environment. If tex, the output is 
taken to be already proper LaTeX markup and included as is. If hide then all 
output is completely suppressed (but the code executed during the weave).


I can see how that could be confusing. All examples of the chunk headers I have 
seen do not use quoted values. Perhaps the above should state Non-quoted 
character values or similar verbiage.

In terms of reporting Terry, Sweave is in the 'utils' package, which is part of 
Base R, therefore under the copyright of The R Foundation. So here is fine.

Regards,

Marc Schwartz

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


Re: [Rd] Question on parsing R code from C

2011-11-15 Thread KR
Simon Urbanek simon.urbanek at r-project.org writes:
 AFAIR you have to evaluate parse(text=...) for that, there is no C-level 
access to parser errors.

Yes that did it, thanks!
 
 If you get a crash, you're not setting up you R correctly. If your R quits 
then you are in non-interactive mode
 and you didn't setup an error handler.

I am really getting a crash for strings with incorrect escapes like when 
evaluating:
parse(text='ggsave(C:\test.png)')
Using R.exe does not result in a crash.
It's really puzzling that all the other parse errors (like rnorm(10a10)) or 
evaluation errors (like idontexists(10)) correctly results in an error string 
an 
no crash. Code that executes correctly works fine as well.
Do you have any suggestion on what may be causing the issue? 

I am initializing R with:
Rf_initEmbeddedR passing progsname, --vanilla and --slave

And I am parsing/evaluating with:
Rf_mkString (protected) passing capture.output(eval(parse(text=code)))
(I also tried with allocVector + Rf_mkChar with no difference)
Followed by:
R_ParseVector(r_cmd, -1, parse_err, R_NilValue) (protected) with r_cmd given by 
the SEXP returned above
And by:
R_tryEvalSilent(VECTOR_ELT(r_expr,i), R_GlobalEnv, eval_err) (protected) 
iterating along r_expr which is given by the SEXP returned above.

I don't perform any other operation at all. R_Interactive is true.

 I prefer using Rf_eval() and try(..., silent=TRUE) - you can check on the 
class of the result to see if there
 was an error.

I actually find it easier (less code) to use R_tryEvalSilent followed by 
R_curErrorBuf in case of error. Are they going to be deprecated?

 BTW: you are asking a lot of questions the are answered in the Rserve FAQ 
(since what you do is exactly what
 Rserve provides) so you may want to have a quick look:
 http://rforge.net/Rserve/faq.html

Thanks a lot, that helped as well!

Plotting works as well but after the window is created it freezes, cannot be 
closed without passing dev.off() command. I understand this is expected 
behavior and that it cannot be changed using Rf_initEmbeddedR and 
Rf_endEmbeddedR.

The only problem I am having (aside from the wrongly escaped string crashes) is 
that if I call:
Rf_initEmbeddedR (to open the global R state) followed by Rf_endEmbeddedR (to 
close the global R state) and then I try to open the global state again with 
Rf_initEmbeddedR I get:
Lost warning messages on stderr and calling other R functions result in hang.
What am I doing wrong?

Thanks a lot for all the suggestions so far, I have made a lot of progress.

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


Re: [Rd] When collected warnings exceeds 50

2011-11-15 Thread Jeffrey Horner
On Thu, Nov 10, 2011 at 11:00 PM, Jeffrey Horner
jeffrey.hor...@gmail.com wrote:
 On Thu, Nov 10, 2011 at 10:54 PM, Jeffrey Horner
 jeffrey.hor...@gmail.com wrote:
 Hi,

 I've been tracking down a memory leak in an rApache application,
 http://data.vanderbilt.edu/rapache/bbplot. The code was deployed in
 2007 and has survived numerous upgrades of both R and rApache
 (including upgrades and bugs in RMySQL). It's written in such a way so
 that web crawlers will download every possible URL the app will
 create. It's not a high-traffic app, but just about every line of code
 is executed at some point during a crawl by Google, Bing, etc.

 Here's the salient point: the app (well, just about all rApache apps)
 sets option warn to 0 to collect all warnings until a request is
 completed. It turns out that some requests will collect more than 50
 warnings, and the result is an apache process that leaks memory until
 finally seg faulting somewhere in one of R's extra packages, if I
 recall correctly.

 After what seems like a month working on this problem, I think I've
 narrowed it down to a simple test case. I'm testing with R-devel
 r57624 on ubuntu linux. Running the following under valgrind:

 R -d valgrind
 options(warn=0)
 for (i in 1:51) factor(1,levels=c(1,1) # duplicate level warningcall

 Missed a closing parenthesis. should be :

 options(warn=0)
 for (i in 1:51) factor(1,levels=c(1,1)) # duplicate level warningcall


 and you should see Invalid read messages. I've narrowed it down to
 vwarningcall_dflt starting a new R context via begincontext()  but
 returning early without calling endcontext() in errors.c:

  svn diff src/main/errors.c
 Index: src/main/errors.c
 ===
 --- src/main/errors.c   (revision 57624)
 +++ src/main/errors.c   (working copy)
 @@ -333,8 +333,11 @@
        char *tr; int nc;
        if(!R_CollectWarnings)
            setupwarnings();
 -       if( R_CollectWarnings  49 )
 +       if( R_CollectWarnings  49 ) {
 +           endcontext(cntxt);
 +           inWarning = 0;
            return;
 +       }
        SET_VECTOR_ELT(R_Warnings, R_CollectWarnings, call);
        Rvsnprintf(buf, min(BUFSIZE, R_WarnLength+1), format, ap);
        if(R_WarnLength  BUFSIZE - 20  strlen(buf) == R_WarnLength)

 This fix eliminates the Invalid read errors, but I'm unsure if it
 fixes my application. I'll find out tomorrow.

The memory leak was occurring in the Cairo package and it is fixed
now, but the issue I spelled out above is still a concern.

Jeff

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


Re: [Rd] Question on parsing R code from C

2011-11-15 Thread Simon Urbanek

On Nov 15, 2011, at 5:39 PM, KR wrote:

 Simon Urbanek simon.urbanek at r-project.org writes:
 AFAIR you have to evaluate parse(text=...) for that, there is no C-level 
 access to parser errors.
 
 Yes that did it, thanks!
 
 If you get a crash, you're not setting up you R correctly. If your R quits 
 then you are in non-interactive mode
 and you didn't setup an error handler.
 
 I am really getting a crash for strings with incorrect escapes like when 
 evaluating:
 parse(text='ggsave(C:\test.png)')
 Using R.exe does not result in a crash.
 It's really puzzling that all the other parse errors (like rnorm(10a10)) or 
 evaluation errors (like idontexists(10)) correctly results in an error string 
 an 
 no crash. Code that executes correctly works fine as well.
 Do you have any suggestion on what may be causing the issue? 
 

Not without seeing the actual code. (And details such as which platform you're 
on).
Note that setup_Rmainloop() is the last to set the SETJMP context target so you 
should make sure the stack is still present after it finished (i.e. you can't 
call it from a sub-function - which Rf_initEmbeddedR does) otherwise error 
without an enclosing context will crash. Or to put it other way round, create a 
context around your parse/eval code (probably the easiest way to do that is to 
use R_ToplevelExec).


 I am initializing R with:
 Rf_initEmbeddedR passing progsname, --vanilla and --slave
 
 And I am parsing/evaluating with:
 Rf_mkString (protected) passing capture.output(eval(parse(text=code)))
 (I also tried with allocVector + Rf_mkChar with no difference)
 Followed by:
 R_ParseVector(r_cmd, -1, parse_err, R_NilValue) (protected) with r_cmd given 
 by 
 the SEXP returned above
 And by:
 R_tryEvalSilent(VECTOR_ELT(r_expr,i), R_GlobalEnv, eval_err) (protected) 
 iterating along r_expr which is given by the SEXP returned above.
 
 I don't perform any other operation at all. R_Interactive is true.
 
 I prefer using Rf_eval() and try(..., silent=TRUE) - you can check on the 
 class of the result to see if there
 was an error.
 
 I actually find it easier (less code) to use R_tryEvalSilent followed by 
 R_curErrorBuf in case of error. Are they going to be deprecated?
 
 BTW: you are asking a lot of questions the are answered in the Rserve FAQ 
 (since what you do is exactly what
 Rserve provides) so you may want to have a quick look:
 http://rforge.net/Rserve/faq.html
 
 Thanks a lot, that helped as well!
 
 Plotting works as well but after the window is created it freezes, cannot 
 be 
 closed without passing dev.off() command. I understand this is expected 
 behavior and that it cannot be changed using Rf_initEmbeddedR and 
 Rf_endEmbeddedR.
 
 The only problem I am having (aside from the wrongly escaped string crashes) 
 is 
 that if I call:
 Rf_initEmbeddedR (to open the global R state) followed by Rf_endEmbeddedR (to 
 close the global R state) and then I try to open the global state again with 
 Rf_initEmbeddedR I get:
 Lost warning messages on stderr and calling other R functions result in 
 hang.
 What am I doing wrong?
 

Nothing. You can initialize R only once.

Cheers,
Simon


 Thanks a lot for all the suggestions so far, I have made a lot of progress.
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 
 

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