gge-ucd / Discussion

Class discussion for R-DAVIS course
0 stars 4 forks source link

Print() Function Meaning #9

Closed brubinoff closed 7 years ago

brubinoff commented 7 years ago

I'm confused as to what the print() function does. If you run the code (for example, 10-2 vs print(10-2)) it returns the exact same output. Why use this function?

Thanks!

Ben

ecbolas commented 7 years ago

I am confused about the same thing! @ryanpeek

ryanpeek commented 7 years ago

Let's go over it in class. But for the record, essentially whenever you run a command or send it to your console, the output for direct calculator type functions is the same as when wrapped in print. Example: 4+4 is shown as 8, and print(4+4) will also be 8.

print becomes helpful when you assign an object using the <-, sometimes you can assign something and it won't display the outcome in your console. To see this object, you would need to type that name, or wrap it in paranthesis. Print can be useful for things like plots, or more complicated function outputs that you are saving (or assigning) to your environment.

vector_of_numbers <- c(10, 20, 30, 40) # This outputs nothing, but you'll see it in your Environment tab print(vector_of_numbers) # prints the object (vector_of_numbers <- c(10, 20, 30, 40) # wrapping in parentheses will also print the output of something