1

I'm trying to knit an RStudio notebook but i'm getting the following error:

"Error in UseMethod("mutate_") : no applicable method for 'mutate_' applied to an object of class "function" Calls: ... mutate -> log_mutate -> .fun -> mutate.default -> mutate_"

with the following lines:

data <- data %>% 
  mutate(
    variable = factor(variable,ordered = FALSE)
  )

The funniest thing is that the R code works just fine and does the expected. Only the knitting doesn't work.

Any thoughts? Thanks in advance!

Filipa
  • 50
  • 6
  • 1
    Do you have `library(dplyr)` in the notebook? Rmarkdown knits in a new environment so packages used in the script need to be explicitly referenced. Alternatively try `dplyr::mutate`. – Peter Nov 30 '21 at 12:56
  • Thank you @Peter! I have ```library(dplyr)``` in the notebook and i tried ```dplyr::mutate``` but i still get this error :( – Filipa Nov 30 '21 at 14:38
  • Could you make the question reproducible by including the minimum code from your Notebook which consistently reproduces the error? I guess this would be the yaml and one code chunk which includes a minimal dataset. – Peter Nov 30 '21 at 15:35
  • 1
    This is because you didn't load `data` in your Markdown document, so that knit finds `utils::data()` function. See https://stackoverflow.com/q/34029611/13513328 – Waldi Apr 02 '22 at 14:52

0 Answers0