1

I know this is the sort of question that is hated in any forum, but I have tried my best: I could not get rid of the error below, so I ended up taking the suggested steps for this issue, de- and reinstalled R and all packages, and it worked! For a short time - now, after having restarted my computer, I receive the same familiar error from a function that I do not directly call and which I find hard to trace ("p"?). As far as I know, the functions I call are not deprecated - it did end up working after cleaning my computer of everything related to R. In addition to de-/reinstalling R, is there a good tip of how to deal with such an issue? Is there a particular information from my system that could help trace this error?

This is my rather simple code which is supposed to set NA's to the maximum value in each pid-group:

require("tidyverse")

list_na <- c("val1","val2")
dftest <- data.frame(pid=c(rep(1,5),rep(0,5)),
                     val1=c(NA,1,1,1,3,NA,NA,3,1,NA),
                     val2=c(NA,1,1,1,3,NA,NA,3,-100,NA))
dftest <- dftest %>% group_by(pid) %>%
  mutate(across(any_of(list_na), ~replace_na(.x, max(.x, na.rm = T))))
dftest

Error message:

Error in `mutate()`:
! Problem while computing `..1 = across(any_of(list_na), ~replace_na(.x,
max(.x, na.rm =   TRUE)))`. Caused by error in `across()`: 
! Problem while computing column `val1`. Caused by error in `p()`: 
! could not find function "p"

I have no idea what p() refers to.

hierb
  • 59
  • 4
  • 3
    I get a different error when I run your code: "could not find function "any_off". It should be `any_of`, not `any_off`. Maybe it depends on your dplyr version what message you get. – MrFlick Nov 16 '22 at 19:02
  • ah sorry, it should be any_of, I added this part manually to the code to after I copied it over - the error message is not affected by this, there is just an additional message that tells me to use any_of / all_of. All of my packages are updated to the most current version – hierb Nov 16 '22 at 19:06
  • 1
    Please edit your question to show exactly what you are running. If I change `any_off` to `any_of` myself, your code runs just fine without errors. Test with `dplyr_1.0.10`. – MrFlick Nov 16 '22 at 19:10
  • any_of() Get no error! – TarJae Nov 16 '22 at 19:11
  • 1
    Another vote for "runs without error after correcting `any_of`" (also dplyr 1.0.10) – Ben Bolker Nov 16 '22 at 19:32

1 Answers1

0

SOLVED! There seems to have been a problem with the packages I had loaded in the background, probably a function defined multiple times which I did not include in my coding sample.

This works:

dftest <- dftest %>%  group_by(pid) %>%
        dplyr::mutate(dplyr::across(dplyr::any_of(list_na), ~tidyr::replace_na(.x, max(.x, na.rm = T))))
hierb
  • 59
  • 4