This question already has answers here:
dplyr::select function clashes with MASS::select
(6 answers)
Closed 1 year ago.
I am encountering a strange problem in using packages MASS and dplyr together in R using RStudio. The following code
library(dplyr)
select(iris, starts_with("Petal"))
works and gives me the right output. But if I try to load MASS package and use the same code
library(MASS)
library(dplyr)
select(iris, starts_with("Petal"))
I get an error
select(iris, starts_with("Petal"))
Error in select(iris, starts_with("Petal")) :
unused argument (starts_with("Petal"))
Is there a known issue with using dplyr with MASS in RStudio. I am loading dplyr after MASS so as not to mask the select from dplyr. I have un-installed and re-installed my RStudio also, but the error persists.
I am using R Version 3.2.2, MASS version - 7.3-45 and dplyr version 0.5.0
Any help would be highly appreciated!
sn248
Both packages have a select function.
Use dplyr::select() or MASS::select() as needed to prevent errors.
Another popular conflict is the dplyr::filter vs signal::filter.
If you don't want to type the package name every time you can type once dselect <- dplyr::select and then use dselect all the time instead.
Related
This question already has answers here:
Error: could not find function ... in R
(10 answers)
Closed 1 year ago.
I want to use spread function from tidyr package but my RStudio says
"Error in spread(., nama_event, created_at) :
could not find function spread"
Therefore, I want to install tidyr package but it doesn't exist in RStudio 1.4.1.
Instead of using spread you should use pivot_longer.
https://tidyr.tidyverse.org/articles/pivot.html
To install a package, you shoud use install.packages.
This question already has answers here:
Error: could not find function ... in R
(10 answers)
Closed 1 year ago.
I am using Google Colab to work on a final project with a set of groupmates. Unfortunately, Colab is not working and I am getting this error. I was able to successfully install and then call the library for the package but when I run the DDPLY code Colab doesn't work.
If anyone can provide insight as to how to fix this it would be greatly appreciated!
It looks like you are loading dplyr and not plyr.
Calling it with either library(plyr); ddply() or plyr::ddply() should solve your issue
I think ddply is not in dplyr (daft I know!) it is in plyr
So you need
library (plyr)
(And on first use a install.packages("plyr") too)
This question already has answers here:
From [package] import [function] in R
(5 answers)
Closed 3 years ago.
In a script I need to load packages tydiverse and gdistance.
gdistance actually loads several other packages and overall mask some functions of the tydiverse (e.g. select).
I tried to rearrange the script by loading the gdistance only when needed and having the related lines at the end of the script.
Anyway one of the very last line I need still use the function tydiverse::select, which is then not found and it throws an error.
Is there a way to make a copy of the R environment before loading the gdistance package so that I can then restore the environment as it was before loading the pakage that induce the problem?
Here are some alternatives:
1) Simply load tidyverse second since the most recently loaded name takes precdence.
library(gdistance)
library(tidyverse)
2) select actually comes from the raster package used by gdistance, not from gdistance itself. Also, in R version 3.6+ library has an exlude= argument to exclude loading specified names. Thus we can write the follwoing to ensure that select will refer to dplyr.
# needs R 3.6+
library(tidyverse)
library(raster, exclude = "select")
library(gdistance)
3) Use dplyr::select to force select to be used from dplyr.
4) detach gdistance and raster before using select and load them back in afterwards (if you still need them).
library(tidyverse)
library(gdistance)
# ... select refers to select from raster
detach("package:gdistance")
detach("package:raster")
# ... select refers to select from dplyr
library(gdistance)
# ... select refers to select from raster
This question already has answers here:
Error: could not find function ... in R
(10 answers)
Error: could not find function "%>%"
(5 answers)
Closed 3 years ago.
I am trying to run a line of code in R using the dplyr package. dplyr is installed and the package appears to have loaded correctly, but does not recognise the %>% function.
The code I am attempting to run is -
reptiledata2 = reptiledata %>% filter (START_YEAR>=1980)
This leads to the error:
Error in reptiledata %>% filter(START_YEAR >= 1980) : could not find function "%>%"
This code has previously worked for me before, but for some reason is not working today. Have also tried to load magrittr package but this does not solve the issue either.
Install or reinstall dplyr package.
install.packages("dplyr")
If does not work, try to remove it and reinstall.
This question already has answers here:
How to find all functions in an R package?
(6 answers)
Closed 7 years ago.
I would like to know if there is a command, using which one can view all the functions that are built into an R package.
For example, let's say I loaded a package into environment:
require(dplyr)
Now, I would like to get a list of all the functions present in the dplyr package.
Is there any way to get such a list?
You can use lsf.str.
For instance:
lsf.str("package:dplyr")
To list all objects in the package use ls
ls("package:dplyr")
Note that the package must be attached.
To see the list of currently loaded packages use
search()
Alternatively calling the help would also do, even if the package is not attached:
help(package = dplyr)
Finally, you can use RStudio which provides an autocomplete function. So, for instance, typing dplyr:: in the console or while editing a file will result in a popup list of all dplyr functions/objects.