我正在尝试使用 Python Faker 库中的一些函数在 R 中构建一个小标题。除了日期,所有工作都正常,日期被replicate()
.
下面是可重现的示例,其中有一个示例,它可以在底部没有复制的情况下正常工作。
我认为这是因为replicate()
是sapply()
with的包装器simplify = "array"
,但是,使用复制副本并没有改变结果(例如replicate2 <- function(n, expr) sapply(intenger(n), eval.parent(substitute(function(...) expr)))
)。
library(tidyverse); library(reticulate)
# Python Faker library
faker <- import("faker")
fake <- faker$Faker()
make_df <- function(N){
txns <- tibble(
date_time = replicate(5, fake$date_time_between(start_date = "-1y",
end_date = "now") %>%
str_extract("[0-9-]*") %>% lubridate::parse_date_time("Ymd"))
)
return(txns)
}
make_df(5)
#> # A tibble: 5 x 1
#> date_time
#> <dbl>
#> 1 1545177600
#> 2 1546473600
#> 3 1537833600
#> 4 1547596800
#> 5 1531008000
fake$date_time_between(start_date = "-1y", end_date = "now") %>%
str_extract("[0-9-]*") %>% lubridate::parse_date_time("Ymd")
#> [1] "2018-07-25 UTC"
由reprex 包(v0.2.1)于 2019 年 2 月 19 日创建
simplify = FALSE
正如 Flick 先生评论的那样,解决方案只是。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句