[英]Tidyverse and dplyr- error package or namespace
I can't seem to get the filter function to work along with the loading of tidyverse.我似乎无法让过滤器 function 与 tidyverse 的加载一起工作。 I have compared code and know that it is correct however I get error messages every time.我已经比较了代码并且知道它是正确的但是我每次都会收到错误消息。 I have checked multiple online resources and none seem to help.我检查了多个在线资源,但似乎没有任何帮助。 I also have updated all of my packages and restarted them.我还更新了所有软件包并重新启动它们。 Any help is appreciated!任何帮助表示赞赏!
This is my code:这是我的代码:
library(tidyverse)
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = Hwy))
filter(mpg, cyl == 8)
filter(diamonds, carat > 3)
Errors:错误:
library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(I,
c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
namespace ‘rlang’ 0.4.2 is already loaded, but >= 0.4.3 is required
In addition: Warning message:
package ‘tidyverse’ was built under R version 3.6.3
filter(mpg, cyl == 8)
Error in filter(mpg, cyl == 8) : object 'cyl' not found
In addition: Warning messages:
1: In data.matrix(data) : NAs introduced by coercion
2: In data.matrix(data) : NAs introduced by coercion
3: In data.matrix(data) : NAs introduced by coercion
4: In data.matrix(data) : NAs introduced by coercion
5: In data.matrix(data) : NAs introduced by coercion
6: In data.matrix(data) : NAs introduced by coercion
filter(diamonds, carat > 3)
Error in filter(diamonds, carat > 3) : object 'carat' not found
Your issue is that tidyverse
is not being loaded into your R session, and so when you call filter
, it is from the stats
package rather than dplyr. Your issue is that tidyverse
is not being loaded into your R session, and so when you call filter
, it is from the stats
package rather than dplyr. This is why it's good practice to use namespaces in R, like dplyr::filter
, so you know exactly which function you are calling.这就是为什么在 R 中使用命名空间是一种很好的做法,例如dplyr::filter
,这样您就可以确切地知道您正在调用哪个 function。
To fix the error loading tidyverse, update the rlang
library:要修复加载 tidyverse 的错误,请更新rlang
库:
update.packages()
And then try然后尝试
dplyr::filter(mtcars, cyl == 8)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.