[R] readline() to vector
Henrik Bengtsson
hb at maths.lth.se
Fri Jan 18 18:16:11 CET 2002
The following code handles the situation when you enter a string of type
"10,20,-10,50":
limStr <- readline("Enter xlim and ylim values: ");
lim <- as.numeric(unlist(strsplit(limStr, ",")));
To parse strings of type "c(10,20,-10,50)" you could strsplit the string
on "c(" and ")" first to get the "10,20,-10,50" part and the proceed as
above.
Cheers
Henrik Bengtsson
Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
Lund Institute of Technology/Lund University, Sweden (+2h UTC)
Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax)
h b @ m a t h s . l t h . s e
http://www.maths.lth.se/matstat/staff/hb/
On Fri, 18 Jan 2002, Agustin Lobo wrote:
>
> Hi!
>
> 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 ?
>
> Thanks
>
> Agus
>
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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