Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simultaneous variable assignment and printing

I was wondering if there was a way to assign a value and print the value to the console succinctly.

x <- 1:5; x

This is how I would presently do this, but I was wondering if there was a way to do it in one statement.

like image 437
Michael Clinton Avatar asked Feb 25 '14 02:02

Michael Clinton


1 Answers

You can try:

(x <- 1:5)

or

print(x <- 1:5)

though that won't work for things like

(names(x) <- letters[1:5])

though for that specific example you can do:

(x <- setNames(x, letters[1:5]))
like image 65
BrodieG Avatar answered Nov 07 '22 15:11

BrodieG