msberends / AMR

Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by using evidence-based methods, as described in https://doi.org/10.18637/jss.v104.i03.
https://msberends.github.io/AMR/
Other
85 stars 14 forks source link

issue with as.ab (amr 1.5) #20

Closed jukkiebah closed 3 years ago

jukkiebah commented 3 years ago

hai

this code works under AMR 1.4, but not with AMR 1.5:

df <- df %>% rename_with(df, .fn = as.ab, .cols = amikacine:voriconazol)

now with AMR 1.5 I get this error:

Error: in .fn(): argument flag_multiple_results must be of class "logical", not "tbl_df/tbl/data.frame"

(greetings, Rogier)

msberends commented 3 years ago

Thx! I’ll look into it.

msberends commented 3 years ago

The error was caused because of a syntactic error at your side I'm afraid 🙂

You wrote

df <- df %>% rename_with(df, .fn = as.ab, .cols = amikacine:voriconazol)

But after a pipe, the data object (df) must be omitted, like this:

df <- df %>% rename_with(.fn = as.ab, .cols = amikacine:voriconazol)
# or even shorter
df <- df %>% rename_with(as.ab, amikacine:voriconazol)

So the error was right, it said that the second argument of as.ab() (which is flag_multiple_results) must be TRUE or FALSE, not a data set.

msberends commented 3 years ago

So that it worked under 1.4.0 was erroneous, it was incorrectly allowed.

msberends commented 3 years ago

Small idea to make your script independent of variable names (assuming that your variables with AB results are of class <rsi>, e.g., using as.rsi()):

df <- df %>%
  rename_with(as.ab, where(is.rsi))

If they aren't already of class <rsi>, you can add this mutate():

df <- df %>%
  mutate(across(where(is.rsi.eligible), as.rsi)) %>%
  # or the good old and way better readable:
  # mutate_if(is.rsi.eligible, as.rsi) %>% 
  rename_with(as.ab, where(is.rsi))
jukkiebah commented 3 years ago

Thanks!! Also for the suggestions. This was a slip-up on my part. It now works perfectly