2

I was analyzing data in a R Markdown file named as "A", and suddenly the group_by() function from dplyr package didn't work as expected anymore. Then I found out the similar problem has been addressed here: Why are my dplyr group_by & summarize not working properly? (name-collision with plyr). The solution is to detach the plyr package.

However, when I tried detach(package:plyr), I got an error message:"Error: package ‘plyr’ is required by ‘Rmisc’ so will not be detached". I was not using "Rmisc" in my current file "A", but "Rmisc" was used by another R Markdown file named as "B" which was also opened.

I finally had to use dplyr::group_by() to solve the problem. And actually I had to put dplyr:: to all the functions I tried to use such as mutate() and select(). This was really annoying!

So, my question is, in Rstudio, how to isolate the installed packages such as "Rmisc" to just a specific file such as "B" where it was needed, while the other files, such as "A" would not be affected? Thanks!

I would greatly appreciate your kind help!

Jeff

Spacedman
  • 92,590
  • 12
  • 140
  • 224
JeffZheng
  • 1,277
  • 1
  • 10
  • 13
  • 1
    One way to deal with this would be to open a separate [project](https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects) for each thing you're working on (this is obviously not a great solution if files "A" and "B" are actually for the same project, but a good work around otherwise) (+ RStudio projects have a lot of other great attributes!) – Lucy Oct 26 '17 at 23:22
  • @Lucy: Thanks a lot for your great suggestions! I will try what you said. – JeffZheng Oct 26 '17 at 23:24
  • @Lucy I followed your suggestion to create a separate project in which I created the new file "A". When I created this project, all other .rmd files were closed automatically by Rstudio. – JeffZheng Oct 27 '17 at 04:44
  • @Lucy Then, I clicked the "File", "Recent Files" to open the file "B" which used "Rmisc" to see whether "B" will affect the new file "A". To my surprise, new file "A" was still affected by the file "B". So, apparently this approach doesn't work well.The only way might be to create a separate project for each .rmd file as you said. But this will be very inconvenient in case we just want to simply open another .rmd file (e.g., one interesting .rmd file from a website) to check some information. – JeffZheng Oct 27 '17 at 05:09
  • Instead of "File" > "Recent Files", you'll want to open "B" as the separate project you created, so you would do "File" > "Recent *Projects*" in order to take advantage of this feature. Essentially, it opens a separate RStudio instance for this project so the packages loaded don't interfere across projects. – Lucy Oct 27 '17 at 14:49
  • @Lucy Great point! Thanks. I will leave this question open for a little while to see whether we can get other opinions/solutions. – JeffZheng Oct 27 '17 at 15:35

0 Answers0