如果有多个语句,则保留返回类型 [英] Rserve return type in case of multiple statements

查看:82
本文介绍了如果有多个语句,则保留返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解Rserve的返回类型(如果有多个命令).例如.

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

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

似乎Rserve仅返回最后一个求值的语句,即rnorm(3).是否可以使用Rserve获得所有三个输出值?

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?

我也想知道我们到底如何在R中获得最后求值表达式的返回值? R中是否有特殊字符可以像在perl中那样获得该字符?

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?

推荐答案

这是正常的R行为,与您在函数中获得的行为相当.例如:

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

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

此处R返回z,因为这是最后执行的操作.要获取所有对象,可以使用列表:

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

这应该适合您的情况:

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.

这篇关于如果有多个语句,则保留返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆