Skip to content

Question about as.numeric with tclvalue

2 messages · Erin Hodgess, Brian Ripley

#
Dear R People:

I have an interactive menu via an Rcmdr extension package which asks
for lower and upper limit to evaluate.

Typically, I use:

assign("a",as.numeric(tclvalue(lowlim)),envir=.GlobalEnv)

and that's fine.

However, if I try to use pi or Inf or -Inf, I get either coerced NAs or NaN.

Does anyone have any suggestions, please?

Thanks,
Erin
PS Happy Easter if you celebrate Easter.
#
It's not clear what is going on here, but one possibility is
[1] NA
Warning message:
NAs introduced by coercion

OTOH, "Inf" works for me.

The difference is that 'Inf' is a standard C99 value (like 1.23), whereas 
'pi' is a variable in R.  So if you want to allow expressions you need to 
parse and eval them, something like

inp <- "pi"
assign("a", eval(parse(text=inp)), .GlobalEnv)

As ever, please see the message footer and remember to supply a 
reproducible example.
On Sun, 23 Mar 2008, Erin Hodgess wrote: