0

I have a sample RMD below. When using render from rmarkdown package, I get an error:

Quitting from lines 25-27 (TRY1.Rmd) 
Error in select(., UID, Homework_10, Exam_3, Section) : 
  unused arguments (UID, Homework_10, Exam_3, Section) 

while when i use the knit to html button, it works. What might be the issue? This question is related to this one but the other question is unanswered. Tried the few suggestions to no avail. Note that the dataframe gradebook contains very many variables. Thanks for your help


---
title: uuu
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(dplyr)
```


```{r}
set.seed(1)
gradebook <- data.frame(
  UID = sample(100000000:999999999, size = 150, replace = FALSE),
  Homework_10 = sample(0:100, size = 150, replace = TRUE),
  Exam_3 = sample(0:100, size = 150, replace = TRUE),
  Section = c(rep('A',times = 80),rep('B', times = 70)))
```


```{r}
gradebook[c(1,2,3,81,82,83),] %>% 
  select(UID, Homework_10, Exam_3, Section)
```

Onyambu
  • 67,392
  • 3
  • 24
  • 53
  • 1
    does it work when you use `dplyr::select` ? – Ronak Shah Jul 20 '20 at 07:20
  • On my Windows computer, both methods work without error message. – Waldi Jul 20 '20 at 08:08
  • Try base R, `gradebook[c(1, 2, 3, 81, 82, 83), c("UID", "Homework_10", "Exam_3", "Section")]` – jay.sf Jul 20 '20 at 08:32
  • @jay.sf. Have a lot of scripts and all the students use select. – Onyambu Jul 20 '20 at 13:03
  • @RonakShah. That is the solution!! One student loads the MASS package, and it seems that my function does not unload it. These causes all the other scripts not to knit. Thanks so much. You could add that as a solution – Onyambu Jul 20 '20 at 13:05
  • Should it be marked as duplicate https://stackoverflow.com/questions/24202120/dplyrselect-function-clashes-with-massselect Or https://stackoverflow.com/questions/46325145/error-with-select-function-from-dplyr ? Or you still think I should add an answer? – Ronak Shah Jul 20 '20 at 13:24
  • @RonakShah technically it should not be as a duplicate. Many will search the issue not realizing that it is a clash. If I knew it was a clash, I wouldnot have asked. I know at times you could search and get duplicates, although I would prefer to have you answer it – Onyambu Jul 20 '20 at 13:46

1 Answers1

1

The issue here was dplyr::select was masked with MASS::select which resulted in error.

Possible ways to overcome this issue are

  1. Restart R and load only dplyr library.
  2. Use dplyr::select instead of just select.
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213