1

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.

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:

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

  • Hi, can you please provide a [minimal reproducible example](https://stackoverflow.com/a/5963610/2414988) so that we can better help you? Also, did you try to run `is.data.table` on the variable that causes the error? – Biblot Oct 19 '19 at 12:19
  • is.data.table(trace.df) evaluates to false. Does that mean, that the trace data I read in, is in the wrong format somehow? A minimal reproducible example would include compiling the whole project and then there is still no guarantee that the error will be reproduced, since the maintainer of the repo doesn't experience the same the problems that I have. – Moostropfen Oct 19 '19 at 12:42
  • 2
    A minimal reproductible example would include a sample of your data that can recreate the error, along with the exact part of the code that produces it (I think we may have already guessed the line that causes the error). See the link I shared. Without it, all we can do is tell you that you are trying to use `data.table` methods on an object that isn't a `data.table`, thus the error. – Biblot Oct 19 '19 at 14:39
  • 1
    I updated my post. I'd be grateful, if you had another look. – Moostropfen Oct 21 '19 at 10:00
  • Thanks, I was able to run this script with the data you provided. However, I didn't have any error. Here's the command I used: `Rscript --vanilla plot_trace.R -m ./log.model.csv ./log.trace.csv`. Can you try to run the script step by step, for example from RStudio, to see where the problem arises and to check the class of `trace.df`? – Biblot Oct 21 '19 at 12:03

2 Answers2

3

UPDATE

I found two problems with this script:

  • The author mixes functions from tidyr and variables of class data.table. These functions will likely return data frames and using data.table syntax on these will cause errors. 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.

  • The unnest function from tidyr has a new interface. The script won't work as is with tidyr version 1.0.0 or later.

Below are the lines I changed to fix the script, using R version 3.6.1 and tidyr version 1.0.0:

  • line 56: added trace.df <- as.data.table(trace.df)
  • line 64: changed to trace.df <- unnest(trace.df, cols)
  • line 65: added 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:

Result plot

Can you run the script step by step in RStudio to check the class of trace.df after each step?

Biblot
  • 695
  • 3
  • 18
  • Thanks for the detailed answer. Unfortunately, after upgrading to 3.6.1 the error still persists. Running `Rscript --vanilla plot_trace.R -m ./log.model.csv ./log.trace.csv` gives me: `Error in strsplit(x, "\\|") : non-character argument Calls: [ ... [.data.table -> eval -> eval -> lapply -> FUN -> strsplit Execution halted` – Moostropfen Oct 21 '19 at 14:58
  • @Moostropfen: The error doesn't persist, it's a new one, caused by the call to `strsplit` on line 62. It seems like the problem with `data.table` was indeed fixed by upgrading to R 3.6.1. Check `trace.df` for non-character values in the columns `value` and `field`, in particular missing values. – Biblot Oct 21 '19 at 15:04
  • 1
    Forget what I wrote. I messed a few things up... I added `trace.df <- as.data.table(trace.df)` as recommended. That gives me `unnest() has a new interface. See ?unnest for details. Try df %>% unnest(c(value, field)), with mutate() if needed Error in :=(CPU, as.integer(CPU)) : 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 -> := Execution halted`. When I remove it, I get the same error message from the beginning. – Moostropfen Oct 21 '19 at 15:12
  • I updated my answer with a new solution. I wasn't using `tidyr` version 1.0.0 while you were, so I wasn't getting the error from the new interface of `unnest`. This new solution should fix your problem! – Biblot Oct 21 '19 at 15:44
0

It looks like the unnest call is creating something that is not a data table.

At line 56 try adding:

trace.df <- as.data.table(trace.df)
Kreuni
  • 302
  • 1
  • 6
  • Calling `unnest` on a `data.table` returns a `data.table`. Try running the examples from `unnest` documentation with a `data.table` instead of a data frame. – Biblot Oct 19 '19 at 14:35
  • 1
    After checking, this is only true for R version 3.6 and later, my bad! – Biblot Oct 21 '19 at 12:30