How to automatically print the value of a variable after assignment?

I read somewhere that there is a way (with some char at the beginning or at the end of the line) that forces the automatic result of printing the expression.

I want to automatically print n, i.e. no input naftern <- 3

n <- 3
n
+4
source share
1 answer

If you put the expression in parentheses, the result will be printed:

(n <- 3)
##[1] 3 

This works because the assignment operator <-returns a value (invisible, which is strange not in the documentation). Putting it in parentheses (either in printor c, or show, or cat(without a new line)) makes it visible.

+12
source

All Articles