On Sep 19, 2009, at 4:48 PM, Nick Matzke wrote:
Hi,
I have a script which I source, which evaluates a changing
expression call hundreds of times. It works, but it prints to
screen each time, which is annoying. There must be simple way to
suppress this, or to use a slightly different set of commands, which
will be obvious to those wiser than I...
Here is a simpler mockup which shows the issue:
x = data.frame(rbind(c(1,2,3),c(1,2,3)))
xnames = c("a", "b", "c")
names(x) = xnames
for(i in 1:length(x))
{
# Create a varying string expression
expr = paste("y = x$", xnames[i], "[1]", sep="")
# evaluate expression
eval(parse(text=print(expr)))
Why are you printing expr? Seems that you are making it difficult to
achieve your goal of quiet execution if you print the expressions
inside the parse function.
# This command prints the expression to screen even when embedded in
a function in a sourced script. I would prefer it didn't!
}
PS: I have to go through this rigamarole:
expr = "y1 = x$c[1]"
eval(parse(text=print(expr)))
Because the following doesn't work, even though it seems like it
should:
expr = "y = x$c[2]"
eval(expr)
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
R-help@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.