简体   繁体   English

R - `:=` 中的错误(变量,as.character(变量))

[英]R - Error in `:=`(variable, as.character(variable))

I'm trying to run an R script, which can be found here with the command plot_trace.R -m./log.model.csv./log.trace.csv . I'm trying to run an R script, which can be found here with the command plot_trace.R -m./log.model.csv./log.trace.csv .

The two csv files can be found here .可以在此处找到两个 csv 文件。

This produces the error:这会产生错误:

Error in `:=`(variable, as.character(variable)) : 
  Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").
Calls: [ -> [.tbl_df -> check_names_df -> :=

Last but not least my sessionInfo() output:最后但并非最不重要的是我的 sessionInfo() output:

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.4

Thanks谢谢

UPDATE更新

I found two problems with this script:我发现这个脚本有两个问题:

  • The author mixes functions from tidyr and variables of class data.table .作者混合了来自tidyr的函数和 class data.table的变量。 These functions will likely return data frames and using data.table syntax on these will cause errors.这些函数可能会返回数据帧,并且在这些函数上使用data.table语法会导致错误。 Unfortunately, some tidyr functions may return data.table when operating on one, but this seems to vary greatly depending on the version of the tidyr package.不幸的是,一些tidyr函数在运行一个时可能会返回data.table ,但这似乎因tidyr package 的版本而有很大差异。

  • The unnest function from tidyr has a new interface.来自tidyrunnest function 有一个新接口。 The script won't work as is with tidyr version 1.0.0 or later.该脚本无法与tidyr版本 1.0.0 或更高版本一起使用。

Below are the lines I changed to fix the script, using R version 3.6.1 and tidyr version 1.0.0:以下是我为修复脚本而更改的行,使用 R 版本 3.6.1 和tidyr版本 1.0.0:

  • line 56: added trace.df <- as.data.table(trace.df)第 56 行:添加了trace.df <- as.data.table(trace.df)
  • line 64: changed to trace.df <- unnest(trace.df, cols)第 64 行:更改为trace.df <- unnest(trace.df, cols)
  • line 65: added trace.df <- as.data.table(trace.df)第 65 行:添加了trace.df <- as.data.table(trace.df)

Original answer原始答案

I was able to run the script on the data you provided without error.我能够在您提供的数据上运行脚本而没有错误。 Both两个都

Rscript --vanilla plot_trace.R -m ./log.model.csv ./log.trace.csv

and

chmod +x plot_trace.R
./plot_trace.R -m ./log.model.csv ./log.trace.csv

produced the following plot:生产了以下 plot:

结果图

Can you run the script step by step in RStudio to check the class of trace.df after each step?您可以在 RStudio 中逐步运行脚本以在每一步之后检查 trace.df 的trace.df吗?

It looks like the unnest call is creating something that is not a data table.看起来unnest调用正在创建不是数据表的东西。

At line 56 try adding:在第 56 行尝试添加:

trace.df <- as.data.table(trace.df)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .jfindClass中的R错误(as.character(driverClass)[1]):java.lang.ClassNotFoundException - R Error in .jfindClass(as.character(driverClass)[1]) : java.lang.ClassNotFoundException R: get(as.character(FUN), mode = “function”, envir = envir) 中的错误: - R: Error in get(as.character(FUN), mode = “function”, envir = envir) : as.character(NA)的R值 - R value of as.character(NA) R .jfindClass(as.character(driverClass)[1])中的错误:找不到类 - R Error in .jfindClass(as.character(driverClass)[1]) : class not found bigmatrix:CreateFileBackedBigMatrix中的错误(as.character(backingfile),as.character(backingpath) - bigmatrix: Error in CreateFileBackedBigMatrix(as.character(backingfile), as.character(backingpath) R中as.character()和as(,“character”)之间有什么区别 - What is the difference between as.character() and as( ,“character”) in R R中日期对象的as.character的一致输出 - Consistent output of as.character for date objects in R As.character返回数字而不是字符串R. - As.character returning numbers instead of strings R 在 R 中为参考类重载 as.character/paste - Overload as.character/paste for reference classes in R 神秘:为什么我添加和减去另一个变量时,data.table中的as.character()函数运行得更快? - Mystery: Why does the as.character() function in a data.table run faster if I add and subtract another variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM