如何在賦值后自動打印變量的值?

[英]How to automatically print the value of a variable after an assignment?


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

我在某處讀到有一種方法(在行的開頭或末尾有一些字符),這會強制表達式的自動打印結果。

I want to automatically print n, i.e. without having to type n after n <- 3

我想自動打印n,即在n < - 3之后不必輸入n

n <- 3
n

1 个解决方案

#1


16  

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

如果將表達式放在括號中,則將打印結果:

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

This works because the assignment operator <- returns the value (invisibly, which strangely is not in the documentation). Putting it in parentheses (or in print or c, or show, or cat (without newline)) makes it visible.

這是有效的,因為賦值運算符< - 返回值(不可見,奇怪的是文檔中沒有)。將它放在括號中(或在print或c,或show或cat(不帶換行符)中)使其可見。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/07/29/814e909b88d1e4335cee271e90f6ba5d.html



 
  © 2014-2022 ITdaan.com 联系我们: