]
On Behalf Of Keith Jewell
Sent: Friday, June 24, 2011 11:49 AM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] How to capture console output in a numeric format
If you don't want the information as character, why are you printing it
rather than storing it in a matrix?
Why not something along the lines
try this:
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))
# convert to numeric
fvals - as.numeric(sub(^.* , , fvals))
fvals
One possibility involves applying a regular expression via gsub:
as.numeric(gsub(^\\[1\\] ,,fvals))
On Friday 24 June 2011 14:39:31 Ravi Varadhan wrote:
Hi,
I would like to know how to capture the console output from running an
algorithm for further analysis. I can capture this using
Johns Hopkins
University
Ph. (410) 502-2619
email: rvarad...@jhmi.edu
-Original Message-
From: jim holtman [mailto:jholt...@gmail.com]
Sent: Friday, June 24, 2011 10:48 AM
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: Re: [R] How to capture console output in a numeric format
try
Try using dput(f) instead of print(f) and
use eval(parse(text=capture.output(...))).
I would tend to use something like
OUTPUTS - list()
fr - function(x) {
on.exit(OUTPUTS[[length(OUTPUTS)+1]] - list(x=x,f=f))
... compute and return f
}
so you don't have to use
Here is one approach (different from capture.output) that I believe
accomplishes what you are trying to do:
frtop - function(){
out - numeric(0)
topenv - environment()
fr - function(x) { ## Rosenbrock Banana function
x1 - x[1]
x2 - x[2]
On Jun 24, 2011, at 11:10 AM, Ravi Varadhan wrote:
Thank you very much, Jim. That works!
I did know that I could process the character strings using regex,
but was also wondering if there was a direct way to get this.
Suppose, in the current example I would like to obtain a 3-column
of Medicine Johns
Hopkins University
Ph. (410) 502-2619
email: rvarad...@jhmi.edu
-Original Message-
From: jim holtman [mailto:jholt...@gmail.com]
Sent: Friday, June 24, 2011 10:48 AM
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: Re: [R] How to capture console output
If you don't want the information as character, why are you printing it
rather than storing it in a matrix?
Why not something along the lines of this...
fr - function(x) { ## Rosenbrock Banana function
on.exit(aMatrix - rbind(aMatrix,(cbind(x1, x2, f
x1 - x[1]
x2 - x[2]
f -
11:49 AM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] How to capture console output in a numeric format
If you don't want the information as character, why are you printing it
rather than storing it in a matrix?
Why not something along the lines of this...
fr - function(x) { ## Rosenbrock
Message-
From: jim holtman [mailto:jholt...@gmail.com]
Sent: Friday, June 24, 2011 10:48 AM
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: Re: [R] How to capture console output in a numeric format
try this:
fr - function(x) { ## Rosenbrock Banana function
+on.exit(print(f))
+x1 - x
On Fri, Jun 24, 2011 at 11:10 AM, Ravi Varadhan rvarad...@jhmi.edu wrote:
Thank you very much, Jim. That works!
I did know that I could process the character strings using regex, but was
also wondering if there was a direct way to get this.
Suppose, in the current example I would like to
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: Re: [R] How to capture console output in a numeric format
try this:
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
On Fri, Jun 24, 2011 at 11:16 AM, William Dunlap wdun...@tibco.com wrote:
Try using dput(f) instead of print(f) and
use eval(parse(text=capture.output(...))).
I would tend to use something like
OUTPUTS - list()
fr - function(x) {
on.exit(OUTPUTS[[length(OUTPUTS)+1]] -
14 matches
Mail list logo