我最初认为分号;
相当于添加一个明确的新行,例如.
x <- 1; y <- 2
和
x <- 1
x <- 2
当然,R documentation似乎并没有区别于语法完整的语句:
分号和新行都可以用来分隔语句.A.
然而,我发现至少在Rstudio服务器中,分号的行为与新行不同.例如:
> temp_a ; temp_b <- 1 ; temp_c <- 2
Error: object 'temp_a' not found
> exists("temp_b")
[1] FALSE
> exists("temp_c")
[1] FALSE
与…相比
> temp_a
Error: object 'temp_a' not found
> temp_b <- 1
> temp_c <- 2
>
> exists("temp_b")
[1] TRUE
> exists("temp_c")
[1] TRUE
为什么会这样?还有什么我应该注意的地方吗?