dhp
dhp

Reputation: 23

why does date() not work after loading lubridate package?

Every day, I use date() function in R to create a new working folder named with today's date. But, it does not work as soon as I load lubridate package. date() works again when I remove the package. What does lubridate do so 'date' function work differently? While loading the lubridate package, the message is:

    Attaching package: ‘lubridate’. The following object is masked from 
    ‘package:base’: date. 

What should be the value of x in date(x) to get today's date and time?

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"

Upvotes: 2

Views: 934

Answers (2)

amonk
amonk

Reputation: 1795

The function date() gets masked out by the function that bears the same name lubridate::date()

A workaround is to use base::date()

Upvotes: 1

dvarelas
dvarelas

Reputation: 988

Basically lubridate contains a function named "date" so when you load the lubridate package you are using date() function from that package and not from the base package.

If you want to use a specific function from lubridate package just type lubridate::"the name of the function goes here" without loading lubridate package.

Upvotes: 2

Related Questions