[R] output values from within a function

Erik Iverson eriki at ccbr.umn.edu
Fri Aug 20 21:43:50 CEST 2010



Maas James Dr (MED) wrote:
> Is it possible to get R to output the value of an expression, that is
> being calculated within a function?  I've attached a very simple
> example but for more complicated ones would like to be able to debug
> by seeing what the value of specific expressions are each time it
> cycles through a loop that executes the expression.  I'm relatively
> new to this so there may be much simpler more elegant ways to do it.
> 
> For example, is there a command I can put within the function
> "funct01" that will output the value of z1 to the screen?

Probably ?cat is what you're looking for.

Also look at the ?debug package, or
http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/


> 
> Thanks
> 
> Jim
> 
> ================================== ## Practice file to try out
> evaluations
> 
> y <- 5
> 
> (x <- y^2)
> 
> funct01 <- function (x,y) {
> 
> z1 <- x + y z2 <- x * y z3 <- x^y
> 
> results <- data.frame (z1=z1, z2=z2, z3=z3) return(results)
> 
> }
> 
> funct01(7,9)
> 
> 
> =============================== Dr. Jim Maas University of East
> Anglia Norwich, UK NR4 7TJ
> 
> [[alternative HTML version deleted]]
> 
> ______________________________________________ R-help at 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.



More information about the R-help mailing list