小编Joh*_*all的帖子

将dplyr :: mutate与R中的lubridate :: ymd_hms组合在一起会导致段错误

我尽可能地搜索与此相关的内容,但在SO或dplyr github上找不到任何内容; 可能是一个新问题,因为下面的代码在今天之前运行良好?

问题在概念上很简单:my_data %>% mutate(x = ymd_hms(x))有时调用,但不总是(即随机调用)导致R因捕获的段错误而崩溃.我已经将问题简化为最简单的形式(也在这里:https://gist.github.com/john-sandall/05c3abb24fc738ddc2ad):

require(lubridate)
require(dplyr)

set.seed(42)
make_some_random_datetimes = function(n) ymd("2015-01-01") + seconds(runif(n, min=0, max=60*60*24*365))

d = data.frame(
  col1 = make_some_random_datetimes(5000),
  col2 = make_some_random_datetimes(5000)
)

do_it = function() {
  d %>% mutate(
    col1 = ymd_hms(col1),
    col2 = ymd_hms(col2)  # for some reason, it only crashes when evaluating 2+ cols, if we removed this line it'd be fine
  )
  return(TRUE)
}

do_it()  # doesn't crash every time...it fails every nth time …
Run Code Online (Sandbox Code Playgroud)

r segmentation-fault lubridate dplyr

7
推荐指数
1
解决办法
788
查看次数

标签 统计

dplyr ×1

lubridate ×1

r ×1

segmentation-fault ×1