Error in UseMethod("select_") : when trying to Knit Rmarkdown

dplyr
rmarkdown

#1

Hi
I'm making my first Rmarkdown document and ran into some trouble at my first attempt to Knit.

Trying to Knit returns this error:

Error in UseMethod("select_") : 
  no applicable method for 'select_' applied to an object of class "function"
Calls: <Anonymous> ... freduce -> <Anonymous> -> select -> select.default -> select_
Execution halted```

for this code:

```{r setup, include = FALSE}
library(tidyverse)
library(ggplot2)
library(readxl)
library(lubridate)
library(skimr)
```

```{r, echo = FALSE}
df %>% 
  select(Age) %>% 
  skim() 
```

Running the code on itself with the tiny little play button works fine. Any ideas? I tried googling the error message but couldn't find anything that made sense to me.

Thank you!


#2

hi @stapperen,
df is a function in the stats package for computing the density of the F-distribution. You want it to be your data frame, but R is calling it as the function. dplyr::select is looking for a data.frame - the error

no applicable method for 'select_' applied to an object of class "function"

is just saying that 'select` doesn't know what to do with a function.

As far as it working in the individual chunk: did you define df as a data.frame in the workspace somewhere outside of your knitr document? If so, R will find it when running the individual chunk with the tiny play button. However, when kniting - R will restart completely. This means Knitr starts with a completely clean environment and your df object is gone. The simple fix is to define df within the body of the knitr document.

Also - I'd suggest changing the name of your data.frame to something more descriptive and try to avoid a name that conflicts with an existing function (like age_df, for example).


Best Practices for Reproducible Research - Should We Show Full Mapping of Raw Data to That Used in Research?
#3

Perfect, thanks! Also, thank you for the tip on workspaces, that wouldve been my next problem, no doubt.


#4

2 posts were split to a new topic: Best Practices for Reproducible Research - Should We Show Full Mapping of Raw Data to That Used in Research?