[R] how to read a free text file into individual variables
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Thu Nov 17 08:32:01 CET 2011
?source
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
haohao Tsing <haohaorain at gmail.com> wrote:
>hi ,I am writing a soft package based on R.
>But when I try to read a configure file showed as below.
>How can I read the parameter in this text file.
>How can I read the parameter into each variable in this file ?
>
>configinfo<-scan(file(configfile),ok=TRUE,n=-1)
>scan seems need every line have same column ?
>configinfo <- readLines(configfile,ok=TRUE,n=-1)
>methodnum <- unlist(strsplit(configinfo[2],":"))[2]
>methodname <- unlist(strsplit(configinfo[3],":"))
>time <- strtrim((unlist(strsplit(configinfo[4],":"))[2]),3)
>
>and
>time is a string "3 "
>and
>strtoi(time) failed and is "[1] NA"
>when
>time <- strtoi(strtrim((unlist(strsplit(configinfo[4],":"))[2]),1))
>time is a integer "6"
>actually this parameter could be a 1 to 4 digital number from 1 to 9999
>How could I can read this kind of variables into my config R file?
>thank you
>
>################################################
>##########config file ###########################
>method=1; # amount of methods
>method1;method2;method3; #name of the method
>time=6 #time intv
>byear=1990 #strar year
>eyear=2010 #end year
>title = "pictitle" #title
>xlab = "xlabinfo" #xlab
>xxlimmin = 0 #x
>xxlimmax = 100 #x
>ylab = "ylabinfo" #
>yylimmin = 0 #
>yylimmax = 100 #
>graph = "phase;discrete;oscillo" #
>################################################
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list