I have a super random error when using group_by in dplyr as follows
dat %>% group_by(variable) %>% mutate(score = score[1])
where dat is a data.frame with factor/character column variable and score is a double. The error I get is this:
Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'character'
- It happens regardless of the name of
variable. - Regardless of the computation (e.g.
score[1]). - I can group by any other variable.
- Both variables seem fine. I can marginally do all sorts of computations with
variableorscore. Variable has only repeated entries "arima" and "prophet", noNAs. - Also, the error message shows up only sometimes. Most often the R session simply terminates due to a fatal error.
It's driving me crazy...
I googled the error and couldn't find good help, except for narrowing it down, which is what I did, i.e. a simple group_by computation. Further, I restarted the R session, restarted the computer, updated my R version and the dplyr package, which is now on version 1.07.
I use R version 4.1.1 on Ubuntu 20.04.3 LTS.
Any thoughts on what could possibly produce this error?
Edit I cannot provide a reproducible sample with simulated data as it only happens with the particular data. Here I uploaded the data that is causing the error https://filebin.net/9pywc544hsmgm2p3
Then run the following code
A <- readRDS("dat.rds") %>%
group_by(variable) %>%
mutate(score = score[1])
Interestingly, if you group by A[1:nrow(A), ] instead of A it works, although it is the same data.
Edit 2: I could now run the computation a couple of times, but at some point I always get a fatal error for the same computation. I get the feeling that this seems specific to my system. So probably I have to reinstall everything.
Edit 3:
Doing as.numeric(score) solves the issue. So it seems something was up with the name attributes of score. However, they do not look suspicious and all have the same name, which is "new_confirmed10".