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

2011-06-27 Thread Keith Jewell
502-2619 > email: rvarad...@jhmi.edu > > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > 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

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 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]] <<- list(x=x,f=f)) >  

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

2011-06-24 Thread Matt Shotwell
> >> Now, I need to tweak your solution to get the 3-column matrix. It > >> would be nice, if there was a more direct way to get the numerical > >> output, perhaps a numeric option in capture.output(). > >> > >> Best, > >> Ravi. > >&

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 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-col

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

2011-06-24 Thread David Winsemius
--- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School 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

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

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

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]

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

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

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 mat

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

2011-06-24 Thread Greg Snow
output a list with the output 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 cons

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

2011-06-24 Thread William Dunlap
June 24, 2011 7:40 AM > To: r-help@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.out

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

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

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 thi

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("^.* ", "", fval

[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 <- fun