Re: [R] How to capture console output in a numeric format

2011-06-27 Thread Keith Jewell
] 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

[R] How to capture console output in a numeric format

2011-06-24 Thread Ravi Varadhan
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 -

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread jim holtman
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Hugo Mildenberger
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Ravi Varadhan
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread William Dunlap
-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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Greg Snow
and the values at each call. Hope this helps, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ravi Varadhan Sent: Friday, June 24, 2011 8:40 AM To: r-help@r-project.org Subject: [R] How to capture console output in a numeric format Hi, I

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread David Winsemius
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Matt Shotwell
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Keith Jewell
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 -

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Ravi Varadhan
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread David Winsemius
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Gabor Grothendieck
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Matt Shotwell
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

Re: [R] How to capture console output in a numeric format

2011-06-24 Thread Gabor Grothendieck
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]] -