[英]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.来自tidyr
的unnest
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:
trace.df <- as.data.table(trace.df)
第 56 行:添加了trace.df <- as.data.table(trace.df)
trace.df <- unnest(trace.df, cols)
第 64 行:更改为trace.df <- unnest(trace.df, cols)
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.