eval中的错误(expr,envir,enclos):为什么将字符串视为函数

时间:2018-12-07 13:08:53

标签: r

我有此命令给定的变量PA_coltypes

> PA_coltypes <- pa.get_coltypes(PA)

现在,如果您想在此处查看其包含的内容:

> PA_coltypes
                                    coltypes
1                CD_TY_TT  = col_character()
2  DA_TT  = col_date(format='%Y%m%d-%H%M%S')
3                   A_ARR  = col_character()
4                   M_ARR  = col_character()
5                  CD_ETS  = col_character()
6                   CD_SI  = col_character()
7                  CD_EFS  = col_character()
8             IDT_ETT_CTR  = col_character()
9             NO_PCI_RCCL  = col_character()
10             CD_DVS_ORI  = col_character()
11              CD_NOR_CG  = col_character()
12                  CD_BT  = col_character()
13             NO_STR_CPB  = col_character()
14             NO_STR_RPQ  = col_character()
15             CD_LET_CPT  = col_character()
16                    MT_DVS  = col_double()
17                    MT_EUR  = col_double()
18         NO_CTR_MTR_FUS  = col_character()
19                CD_PCEC  = col_character()
20         CD_CRV_CIA_ORI  = col_character()
21             CD_TY_PCEC  = col_character()

然后,当我要像这样评估此表达式时:

> eval(parse(text=paste("cols (",toString(PA_coltypes$coltypes),")")))

显示此错误

  

eval(expr,envir,enclos)中的错误:找不到函数“ cols”

它说cols是一个错误的函数。

请如何解决此错误?

1 个答案:

答案 0 :(得分:0)

来自eval docs

  

eval在envir指定的环境中评估expr参数   并返回计算值。如果未指定envir,则   默认值为parent.frame()(调用eval的环境是   制造)。

parse返回表达式expression(cols (...eval尝试对其求值。如果R看到cols(args),则它看起来像一个函数,因此R试图找到它,但找不到,并且抛出错误。