t作为R中全局变量的名称:不可能吗? [英] t as a name of the global variable in R: impossible?

查看:77
本文介绍了t作为R中全局变量的名称:不可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用t作为R中全局变量的名称,但是它不允许我使用.

I want to use t as a name of the global variable in R but it does not let me.

sq1=function() {
  t<<-7
}

我收到以下错误:

Error in sq1() : cannot change value of locked binding for 't'

我该如何克服?

推荐答案

<<-在基本程序包中找到了t且已被锁定,但是您仍然可以通过在全球环境:

<<- has found the t in the base package and that is locked but you can still do it by specifying that you want t in the Global Environment:

f <- function() .GlobalEnv$t <- 7
f()

或者使用:assign("t", 7, .GlobalEnv).

这篇关于t作为R中全局变量的名称:不可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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