Rserve return type in case of multiple statements

邮差的信 提交于 2019-12-08 05:11:18

问题


Hi i dont quite understand the return type of Rserve in case of multiple command. eg.

a<-rnorm(10);a[4];rnorm(3)

it seems Rserve only returns the last evaluated statement,i.e. rnorm(3). Is it possible to get all the three output values with Rserve?

Also i am interested to know how exactly in R can we get the return value of last evaluated expression? Is there a special character in R to get that like in perl?


回答1:


This is normal R behavior, comparable to the behavior you get in a function. For example:

spam = function(x, y) {
  z = x + y
}

Here R returns z, because this was the last operation performed. To get all objects you can use a list:

spam = function(x, y) {
  z = x + y
  list(x,y,z)
}

This should work in your case:

a<-rnorm(10);list(a,a[4],rnorm(3))

In addition, I do not know of a way to extract the last performed expression, but I would not recommend using it anyway. This kind of syntax only makes the flow of the program harder to read, and does not save you any time.



来源:https://stackoverflow.com/questions/10412720/rserve-return-type-in-case-of-multiple-statements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!