Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"parse_dt" not resolved from current namespace (lubridate)

I started getting this error message with the lubridate package:

as.Date(ymd_hms("2014-1-1 12:31:15"))

Error in .Call("parse_dt", x, format, TRUE) : "parse_dt" not resolved from current namespace (lubridate)

I have never encountered this before, and I can only create this error when I use lubridate deep within a long script (several nested functions in a package actually) - and I have no idea which line is causing the issue (I have been debugging for hours now without any luck).

Also, it seems to only occur when I use Rstudio, not when I run the same code in an Rgui.

Once it occurs, I have to restart R for lubridate to work again. Also, after it occurs, I have this object in my global environment:

> ls()
[1] "oldLC"
> oldLC
[1] "English_Australia.1252"

I know I am supposed to post errors that can be reproduced, but I cannot reproduce this myself and am hoping for pointers where to look!

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1]  LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] HIEv_0.3        RODBC_1.3-10    maptools_0.8-27 sp_1.0-14       stringr_0.6.2  
[6] plyr_1.8        RCurl_1.95-4.1  bitops_1.0-6    rjson_0.2.13    lubridate_1.3.3
[11] roxygen2_3.0.0 

loaded via a namespace (and not attached):
[1] brew_1.0-6      codetools_0.2-8 digest_0.6.4    foreign_0.8-57  grid_3.0.2     
[6] lattice_0.20-24 memoise_0.1     tools_3.0.2   
like image 667
Remko Duursma Avatar asked Jan 08 '14 00:01

Remko Duursma


1 Answers

I have not found an explanation for the behavior described here. I have, however, found a minimal example to replicate the problem and a way to prevent its recurrence in my scripts.

I created the following file named "CODE-TEST-Lubridate2.R".

## LOAD PACKAGES
library(plyr) # Important to load plyr before dplyr due to function masking.
library(dplyr)
library(lubridate)

dateTemp <- mdy("01-01-1910")

## Cleanup
pkgs <- names(sessionInfo()$otherPkgs)
pkgs <- paste('package:', pkgs, sep = "")
lapply(pkgs, detach, character.only = TRUE, unload = TRUE, force = TRUE)

When I source the file, then source a second time with the following command,

source("data_raw/CODE-TEST-Lubridate2.R")

an error occurs, terminating execution, and I receive the following error message:

Error in .Call("parse_dt", x, format, TRUE, FALSE) : 
"parse_dt" not resolved from current namespace (lubridate)

When I remove package:plyr and package:dplyr from the cleanup script,

 ## Cleanup
exceptPkgs <- c("plyr", "dplyr")
pkgs <- names(sessionInfo()$otherPkgs)
pkgs <- pkgs[ which( !(names(sessionInfo()$otherPkgs) %in% exceptPkgs ) ) ]
pkgs <- paste('package:', pkgs, sep = "")
lapply(pkgs, detach, character.only = TRUE, unload = TRUE, force = TRUE)

meaning that I leave plyr and dplyr loaded, as-is, The error no longer occurs.

(Using R 3.2.4, RStudio 0.99.896, dplyr 0.4.3, lubridate 1.5.6, plyr 1.8.3)

like image 177
SoFarther Avatar answered Sep 21 '22 14:09

SoFarther