Skip to content

as.numeric with tclvalue redux

4 messages · Sundar Dorai-Raj, Peter Dalgaard, Erin Hodgess

#
Hi again R People:

This works fine:
[1] 4.5
[1] NA
Warning message:
NAs introduced by coercion
Is anyone aware of a way around this, please?

thanks,
Erin
#
Erin Hodgess said the following on 3/24/2008 10:39 AM:
Does this help?

eval.tclvalue <- function(x, ...) {
   x <- type.convert(tclvalue(x), as.is = TRUE)
   if(is.character(x) && exists(x, ...)) {
     get(x)
   } else {
     x
   }
}

a <- tclVar("4.5")
b <- tclVar("pi")
c <- tclVar("abcd")

eval.tclvalue(a)
eval.tclvalue(b)
eval.tclvalue(c)

HTH,

--sundar
#
Erin Hodgess wrote:
Brian already told you: Parse and eval.

 > eval(parse(text=as.character(tclvalue(tclVar("pi")))))
[1] 3.141593

(Beware: Depending on the environment in which you eval(), strange 
things can happen if you use the name of an internal variable in your 
function)

What happened with the Inf issue? I can't reproduce that:

 > as.numeric(as.tclObj("Inf"))
[1] Inf
#
Thank you!
On 3/24/08, Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote: