问题
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