Another newbie question for you all:
In a function, say I have:
countme <- function() {
for(i in 1:10) {
i
}
}
How do I get R to print "i" as it runs (e.g. By calling
"countme") -- right
now it seems to supress most output. On a related note, my program uses
remove.vars, which always prints its output -- how to I *supress* that
output?
Thanks!
--j
--
Jonathan A. Greenberg, PhD
NRC Research Associate
NASA Ames Research Center
MS 242-4
Moffett Field, CA 94035-1000
Office: 650-604-5896
Cell: 415-794-5043
AIM: jgrn307
MSN: jgrn307 at hotmail.com
On Sun, 2006-09-24 at 11:31 -0700, Jonathan Greenberg wrote:> Another newbie question for you all: > > In a function, say I have: > > countme <- function() { > for(i in 1:10) { > i > } > } > > How do I get R to print "i" as it runs (e.g. By calling "countme") -- right > now it seems to supress most output. On a related note, my program uses > remove.vars, which always prints its output -- how to I *supress* that > output? > > Thanks!You need to explicitly print() the value. Thus: countme <- function() { for(i in 1:10) { print(i) } }> countme()[1] 1 [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 HTH, Marc Schwartz
Marc Schwartz said the following on 9/24/2006 1:56 PM:> On Sun, 2006-09-24 at 11:31 -0700, Jonathan Greenberg wrote: >> Another newbie question for you all: >> >> In a function, say I have: >> >> countme <- function() { >> for(i in 1:10) { >> i >> } >> } >> >> How do I get R to print "i" as it runs (e.g. By calling "countme") -- right >> now it seems to supress most output. On a related note, my program uses >> remove.vars, which always prints its output -- how to I *supress* that >> output? >> >> Thanks! > > You need to explicitly print() the value. Thus: > > countme <- function() { > for(i in 1:10) { > print(i) > } > } > >> countme() > [1] 1 > [1] 2 > [1] 3 > [1] 4 > [1] 5 > [1] 6 > [1] 7 > [1] 8 > [1] 9 > [1] 10 > > HTH, > > Marc Schwartz > > ______________________________________________ > R-help at stat.math.ethz.ch 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.(Answering "remove.vars" question) Please read ?remove.vars. (You neglected to mention this function is part of the gdata package.) There is an "info" argument you want to set to FALSE. HTH, --sundar
On Sun, 2006-09-24 at 14:14 -0500, Sundar Dorai-Raj wrote:> > Marc Schwartz said the following on 9/24/2006 1:56 PM: > > On Sun, 2006-09-24 at 11:31 -0700, Jonathan Greenberg wrote: > >> Another newbie question for you all: > >> > >> In a function, say I have: > >> > >> countme <- function() { > >> for(i in 1:10) { > >> i > >> } > >> } > >> > >> How do I get R to print "i" as it runs (e.g. By calling "countme") -- right > >> now it seems to supress most output. On a related note, my program uses > >> remove.vars, which always prints its output -- how to I *supress* that > >> output? > >> > >> Thanks! > > > > You need to explicitly print() the value. Thus: > > > > countme <- function() { > > for(i in 1:10) { > > print(i) > > } > > } > > > >> countme() > > [1] 1 > > [1] 2 > > [1] 3 > > [1] 4 > > [1] 5 > > [1] 6 > > [1] 7 > > [1] 8 > > [1] 9 > > [1] 10 > > > > HTH, > > > > Marc Schwartz> > (Answering "remove.vars" question) > > Please read ?remove.vars. (You neglected to mention this function is > part of the gdata package.) There is an "info" argument you want to set > to FALSE.Thanks for noticing my oversight Sundar. Marc