为什么加载 lubridate 包后 date() 不起作用?
why does date() not work after loading lubridate package?
每天,我都使用 R 中的 date() 函数创建一个以今天的日期命名的新工作文件夹。但是,一旦我加载 lubridate 包,它就不起作用了。当我删除包时,date() 再次工作。 lubridate 的作用是什么 'date' 功能有什么不同?加载 lubridate 包时,消息为:
Attaching package: ‘lubridate’. The following object is masked from
‘package:base’: date.
date(x) 中 x 的值应该是多少才能得到今天的日期和时间?
date() #works well
library(lubridate)
date() #does not work now. Error Msg: Error in as.POSIXlt(x, tz = tz(x)) :
#argument "x" is missing, with no default
detach("package:lubridate", unload=TRUE)
date() #now it works again without "x"
函数 date()
被同名函数 lubridate::date()
屏蔽了
解决方法是使用 base::date()
基本上 lubridate 包含一个名为 "date" 的函数,因此当您加载 lubridate 包时,您使用的是该包中的 date()
函数,而不是基础包中的函数。
如果您想使用 lubridate 包中的特定功能,只需键入 lubridate::"the name of the function goes here"
而无需加载 lubridate 包。
每天,我都使用 R 中的 date() 函数创建一个以今天的日期命名的新工作文件夹。但是,一旦我加载 lubridate 包,它就不起作用了。当我删除包时,date() 再次工作。 lubridate 的作用是什么 'date' 功能有什么不同?加载 lubridate 包时,消息为:
Attaching package: ‘lubridate’. The following object is masked from
‘package:base’: date.
date(x) 中 x 的值应该是多少才能得到今天的日期和时间?
date() #works well
library(lubridate)
date() #does not work now. Error Msg: Error in as.POSIXlt(x, tz = tz(x)) :
#argument "x" is missing, with no default
detach("package:lubridate", unload=TRUE)
date() #now it works again without "x"
函数 date()
被同名函数 lubridate::date()
解决方法是使用 base::date()
基本上 lubridate 包含一个名为 "date" 的函数,因此当您加载 lubridate 包时,您使用的是该包中的 date()
函数,而不是基础包中的函数。
如果您想使用 lubridate 包中的特定功能,只需键入 lubridate::"the name of the function goes here"
而无需加载 lubridate 包。