[prev in list] [next in list] [prev in thread] [next in thread]
List: r-help
Subject: [R] strange sprintf() behaviour ?
From: ryszard.czerminski () pharma ! novartis ! com
Date: 2003-10-31 19:39:17
[Download RAW message or body]
This is quite strange behaviour - at least for R-novice as myself....
Consider this:
> testf <- function() { x <-2; sprintf("%s %f", "x =", x); return(x) }
> result <- testf()
> testf <- function() { x <-2; sprintf("%s %f", "x =", x) }
> result <- testf()
> testf()
[1] "x = 2.000000"
Apparently adding return() statement and invoking function like this
"result <- testf()"
suppresses output from sprintf()
Output from print() is NOT suppressed:
> testf <- function() { x <-2; print(c("x =", x)) }
> result <- testf()
[1] "x =" "2"
> testf <- function() { x <-2; print(c("x =", x)); return(x) }
> result <- testf()
[1] "x =" "2"
Is there a way to use sprintf() inside a function ?
I guess I can say: print(sprintf()) - is it the only solution for this ?
R
[[alternative HTML version deleted]]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic