[R] SUMMARY: readline() to vector

Agustin Lobo alobo at ija.csic.es
Sat Jan 19 12:01:46 CET 2002


Thanks to all who answered my
question (appended to this message). Two solutions:

1. If the user answers with the 4 lim values (i.e., 10,20,1,100),
  limStr <- readline("Enter xlim and ylim values: ");
  lim <- as.numeric(unlist(strsplit(limStr, ",")));

2. If the user answers in R vector notation (i.e., c(10,20,1,100) )
  limStr <- readline("Enter xlim and ylim values: ")
  lim <- eval(parse(text=limStr)

Note that
as.numeric(limStr) or as.numeric("c(10,20,-10,50)")

do not work:
[1] NA
Warning message: 
NAs introduced by coercion 

Agus

####################################
ORIGINAL QUESTION:
I'm trying to use readline() to ask for xlim() and ylim() values
for a subsequent plot. I'm doing:

lim <- readline("Enter xlim and ylim values: ")

then would like to use the values in lim for a plot:

plot(etc, xlim=lim[1:2],ylim=lim[3:4])

The problem is that lim is a character,i.e.,

"10,20,-10,50"
or
"c(10,20,-10,50)"

depending on the input to the readline request.

My question is: how can I transform either "10,20,-10,50" or
"c(10,20,-10,50)" into a numeric vector ?

####################################################




Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list