-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Ravi Varadhan
Sent: Friday, June 24, 2011 7:40 AM
To: r-help at r-project.org
Subject: [R] How to capture console output in a numeric format
Hi,
I would like to know how to capture the console output from
running an algorithm for further analysis. I can capture
this using capture.output() but that yields a character
vector. I would like to extract the actual numeric values.
Here is an example of what I am trying to do.
fr <- function(x) { ## Rosenbrock Banana function
on.exit(print(f))
x1 <- x[1]
x2 <- x[2]
f <- 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
f
}
fvals <- capture.output(ans <- optim(c(-1.2,1), fr))
Now, `fvals' contains character elements, but I would like to
obtain the actual numerical values. How can I do this?
Thanks very much for any suggestions.
Best,
Ravi.
-------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of
Medicine Johns Hopkins University
Ph. (410) 502-2619
email: rvaradhan at jhmi.edu<mailto:rvaradhan at jhmi.edu>
[[alternative HTML version deleted]]