0

I am getting this error when I run my script.

Script:

secondata<-as.data.frame(data)
secondata$R <- as.factor(secondata$row)    
secondata$C <- as.factor(secondata$col)    
m0 <- SpATS(response =  "PH", spatial = ~ SAP(col, row, nseg = c(10,20)),    
            genotype = "geno", random = ~ R + C, 
            data = secondata, control = list(tolerance = 1e-03))
pred1.m0 <- predict(m0, newdata = secondata)

Dataset is arranged as follows

> str(secondata)
Classes ‘data.table’ and 'data.frame':  397 obs. of  9 variables:
 $ block      : int  1 1 1 1 1 1 1 1 1 1 ...
 $ geno       : chr  "CMED_155" "CMED_CoCheck01_ANTALIS" "CMED_303" "CMED_306" ...
 $ rip        : int  0 1 0 0 0 0 2 0 1 0 ...
 $ row        : int  1 2 3 4 5 6 7 8 9 10 ...
 $ col        : int  1 1 1 1 1 1 1 1 1 1 ...
 $ environment: chr  "Italy" "Italy" "Italy" "Italy" ...
 $ PH         : num  71 66 116 118 85 ...
 $ R          : Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ C          : Factor w/ 5 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
 - attr(*, ".internal.selfref")=<externalptr>

Error that I am getting:

Error in `[.data.table`(newdata, , na.terms) : 
  j (the 2nd argument inside [...]) is a single symbol but column name 'na.terms' is not found. Perhaps you intended DT[, ..na.terms]. This difference to data.frame is deliberate and explained in FAQ 1.1.

The script has always worked until today. Can anyone help me figure out what the problem is?

r2evans
  • 141,215
  • 6
  • 77
  • 149
Anto
  • 1
  • It's hard to help without a reproducible example. – s_baldur May 08 '23 at 11:01
  • From @madmad123: If the script has always worked prior to today: Did you try to restart R and re-run the code? Maybe something funny in the coding has happened. – r2evans May 08 '23 at 13:14
  • Welcome to SO, Antonia Mores! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (you've provided some, please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans May 08 '23 at 13:18
  • But to my point about data, please do not post (only) an image of code/data/errors: it breaks screen-readers and it cannot be copied or searched (ref: https://meta.stackoverflow.com/a/285557 and https://xkcd.com/2116/). Please include the code, console output, or data (e.g., `data.frame(...)` or the output from `dput(head(x))`) directly into a [code block]. – r2evans May 08 '23 at 13:18
  • 1 - According to your code `secondata` isn't supposed to be a `data.table` class as you converted it to a `data.frame`, so your output is not related to your code before it. 2 - you haven't specified which part of the code caused the error. First, you showed your code and an output and then mentioned some seemingly unrelated error - this is not now you present a problem if you want to get help – David Arenburg May 09 '23 at 09:23
  • I want to apologize for not providing detailed information, I'm new and I didn't know how to do it. @r2evans you were right, something funny in the coding has happened! Thanks for all the advice, next time I'll know how to do it. – Anto May 09 '23 at 13:39

0 Answers0