-2

I was trying to run Rscript dosth.R in the command line. In the script, I used select function from dplyr package. I got the following error message:

Error in UseMethod("select_") :
no applicable method for 'select_' applied to an object of class "factor"
Calls: %>% ... withVisible -> -> select -> select.default -> select_
Execution halted

However, I could successfully run the main function inside this "dosth.R" script in RStudio.

I want to solve this problem because eventually I would like to put all the codes in a script which can be run in the command line.

I wonder whether you have met this problem and would greatly appreciate your kind help.

Artem
  • 3,304
  • 3
  • 18
  • 41
JeffZheng
  • 1,277
  • 1
  • 10
  • 13
  • Would it be possible for you to share the code for "dosith.R" if it doesn't have any sensitive data? Then I can try to reproduce the issue you have. Perhaps using a service such as: https://pastebin.com/ – Jas Sep 29 '18 at 03:13
  • Please share sample of your data using `dput()` (not `str` or `head` or picture/screenshot) and the code you're working on so others can help. See more here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1 – Tung Sep 29 '18 at 04:16

1 Answers1

0

The problem is that somewhere in your code you redifined data.frame object into factor. The simulation below throws exactly the same error as you defined:

library(dplyr)
data(iris)
iris <- factor(1:10)
iris %>% select(Sepal.Width)

Error in UseMethod("select_") : no applicable method for 'select_' applied to an object of class "factor" Calls: %>% ... withVisible -> -> select -> select.default -> select_ Execution halted

So please check and remove data.frame -> factor transformation from dosth.R file.

Artem
  • 3,304
  • 3
  • 18
  • 41