"找不到功能"只有在R调试器中

时间:2015-03-27 16:53:06

标签: r debugging

我不时遇到这种情况,但这是我第一次有简单的可重复的例子。事实上,这个例子涉及rubridate,我相信是巧合的。在R --vanilla会议

library(lubridate)
ymd("2001-02-02")
# [1] "2001-02-02 UTC"
# so far so good
debug(ymd)
ymd("2001-02-02")
# debugging in: ymd("2001-02-02")
# Error in ymd("2001-02-02") : could not find function ".parse_xxx"

ymd没有任何问题,我试图学习一些东西。但是当你实际调试时会发生这种情况,这很烦人。调试器错误或我错过了什么?

版本信息

    > R.version
               _                           
platform       x86_64-apple-darwin13.4.0   
arch           x86_64                      
os             darwin13.4.0                
system         x86_64, darwin13.4.0        
status                                     
major          3                           
minor          1.2                         
year           2014                        
month          10                          
day            31                          
svn rev        66913                       
language       R                           
version.string R version 3.1.2 (2014-10-31)
nickname       Pumpkin Helmet  

and session infor per @Joshua Urlich评论

  > sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] lubridate_1.3.3

loaded via a namespace (and not attached):
[1] digest_0.6.4  memoise_0.2.1 plyr_1.8.1    Rcpp_0.11.3   stringr_0.6.2

由于

2 个答案:

答案 0 :(得分:4)

看起来可能与使用{}未定义的功能有关。目前的实施是:

ymd <- function(..., quiet = FALSE, tz = "UTC", locale = Sys.getlocale("LC_TIME"),  truncated = 0)
  .parse_xxx(..., orders = "ymd", quiet = quiet, tz = tz, locale = locale,  truncated = truncated)

如果我解压缩源代码并将实现更改为:

,则debug尝试有效
ymd <- function(..., quiet = FALSE, tz = "UTC", locale = Sys.getlocale("LC_TIME"),  truncated = 0)
{  .parse_xxx(..., orders = "ymd", quiet = quiet, tz = tz, locale = locale,  truncated = truncated)}

在进行上述更改之前,我能够复制该问题。制作完成后,我得到:

> require(lubridate); debug(ymd); ymd("2015-01-01")
Loading required package: lubridate
debugging in: ymd("2015-01-01")
debug: {
    .parse_xxx(..., orders = "ymd", quiet = quiet, tz = tz, locale = locale, 
        truncated = truncated)
}
Browse[2]> 
debug: .parse_xxx(..., orders = "ymd", quiet = quiet, tz = tz, locale = locale, 
    truncated = truncated)
Browse[2]> 
exiting from: ymd("2015-01-01")
[1] "2015-01-01 UTC"

答案 1 :(得分:3)

不是解决方案或解释,而是潜在的解决方法:

trace(ymd, browser)

然后:

> ymd("2001-02-02")
Tracing ymd("2001-02-02") on entry 
Called from: eval(expr, envir, enclos)
Browse[1]> n
debug: .parse_xxx(..., orders = "ymd", quiet = quiet, tz = tz, locale = locale, 
    truncated = truncated)
Browse[2]> 

我可以在Win7 R3.1.2 / RStudio上重新创建错误。我希望用trace重新创建问题以试图解决问题,但该函数的任何trace都会破坏问题......