Michael Clinton
Michael Clinton

Reputation: 655

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.

Upvotes: 9

Views: 1545

Answers (1)

BrodieG
BrodieG

Reputation: 52687

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]))

Upvotes: 10

Related Questions