Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling summary() from within a function does not output anything

Tags:

r

Why doesn't this function:

test <- function(somebool = FALSE) {

        mydata<-read.csv("mycsvfile.csv")
        if(somebool){
                print("somebool")
                summary(mydata)
        }
        mydata
}

outdata<-test(somebool=TRUE)
print("head")
head(outdata)

print the summary within the function call? it does print the "somebool" just before it, but not the summary.

Thanks a lot for your help.

like image 792
elelias Avatar asked Jul 18 '26 15:07

elelias


1 Answers

You're calling the function summary but not printing the result. Just change it to:

 print(summary(mydata))
like image 197
David Robinson Avatar answered Jul 21 '26 06:07

David Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!