[Rd] R_ParseVector problem: it's cutting off after the decimal point
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Mar 20 22:37:12 CET 2008
There are so many things that might be going on here that I at least can't
do more than guess pretty blindly.
First, you are assuming that this is a parser issue, but that's not proved
by your test -- it might be a printing issue, which potentially involves
deparsing. So I would have at least evaluated the expression and printed
the result (via printf, not PrintValue).
I noticed that you did not check the parse status so we don't know if this
parsed completely.
This could well be a locale issue: we don't have a complete program and
you are in a non-English locale. The setting of the locale category
LC_NUMERIC does affect this, and I would not expect embedded R to work
unless that was 'C'.
Here's a test that points to the locale issue:
> Sys.setlocale("LC_NUMERIC", "german")
[1] "German_Germany.1252"
Warning message:
In Sys.setlocale("LC_NUMERIC", "german") :
setting 'LC_NUMERIC' may cause R to function strangely
> foo <- parse(text="x <- c(1.234,-3.45)")
> attributes(foo) <- NULL
> foo
expression(x <- c(1, -3))
So my guess it is an error in the environment you are using for embedded
R.
On Wed, 19 Mar 2008, Roland Boubela wrote:
> Dear all,
>
> my aim is to integrate R in an interactive visualisation software
> called Bulk Analyzer developed by VrVis (http://www.vrvis.at).
>
> the code:
>
> SEXP e, tmp;
> ParseStatus status;
>
> PROTECT(tmp = mkString("x <- c(1.234,-3.45)"));
> PrintValue(tmp);
> PROTECT(e = R_ParseVector(tmp, -1, &status, R_NilValue));
> PrintValue(e);
> UNPROTECT(2);
>
> produces the following output:
>
> [1] "x <- c(1.234,-3.45)"
>
> expression(x <- c(1, -3))
>
>
> I'm using MS Visual C++. The code works fine in a small test project
> with the same R startup settings (attached) as in the Bulk Analyzer
> project.
> Is there any setting or condition for this parser behaviour?
>
> Kind regards,
> Roland N. Boubela
>
>
>> sessionInfo()
> R version 2.6.2 (2008-02-08)
> i386-pc-mingw32
>
> locale:
> German_Austria.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
> ================================================
> // init R
> Rf_initEmbeddedR(0, NULL);
>
> Rstart Rp = &rp;
> R_DefParams(Rp);
>
> // root of the R installation
> Rp->rhome = get_R_HOME();
>
> // root of the users directory
> Rp->home = getRUser();
>
> // UImode: RGui, RTerm, LinkDLL
> Rp->CharacterMode = LinkDLL;
>
> // function which reads input for R from a console
> Rp->ReadConsole = myReadConsole;
>
> // function which writes output from R to a console
> Rp->WriteConsole = NULL;
> Rp->WriteConsoleEx = myWriteConsoleEx;
>
> // called during i/o, eval, graphics in ProcessEvents
> Rp->CallBack = myCallBack;
>
> // handles messages for the user from R
> Rp->ShowMessage = myShowconcise Message;
>
> // user interaction: a user is asked a question an should answer
> with YesNoCancel (maybe dialog)
> Rp->YesNoCancel = myYesNoCancel;
>
> // on R state changed: busy(=1)/idle(=0)
> Rp->Busy = myBusy;
>
> Rp->home = getRUser();
>
> // R-Settings...
> Rp->R_Quiet = (Rboolean)FALSE;
> Rp->R_Interactive = (Rboolean)TRUE;
> Rp->RestoreAction = SA_RESTORE;
> Rp->SaveAction = SA_NOSAVE;
>
> // our parameters
> R_SetParams(Rp);
> R_set_command_line_arguments(0, NULL);
>
> GA_initapp(0, NULL);
> readconsolecfg();
>
> /// run_Rmainloop() starting in a different thread
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at 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, UK Fax: +44 1865 272595
More information about the R-devel
mailing list