This is in part answered by FAQ 7.21.
The most important part of that answer is at the bottom where it says
that it is usually better to use a list.
It may be safer to use a list for your case so that other important
variables do not become masked (hidden by the global variables you
just created)
Well, OK, but do note that strsplit() is vectorized, so
z <- strplit(textlines) ## provides a list of splits for each line
would be faster for large files.
However, to add to what Jeff said, it is hard for me to see how your
approach will not lead to problems. For example, what if there are sev
Hi April,
Try this:
# this could be done from a file
textlines<-read.table(text="color=green
shape=circle
age=17
name=Jim",
stringsAsFactors=FALSE)
for(i in 1:length(textlines)) {
nextline<-unlist(strsplit(textlines[i,1],"="))
assign(nextline[1],nextline[2])
}
color
[1] "green"
shape
[1] "ci
Yes. But you should be careful.
"source" is the best way, especially if you put the symbols in a dedicated
environment instead of the global environment to avoid your program getting
stomped on by your input file.
On October 3, 2019 11:58:51 PM PDT, April Ettington
wrote:
>Let's say I am pars
Let's say I am parsing a file with a list of parameters followed by an
equal sign, and their corresponding values, eg:
color=green
shape=circle
and I want to use this information to create a variable called color with
the value 'green' and a variable shape with the value 'circle'. However, I
als
5 matches
Mail list logo