list vs. data.frame in gen.data.frame
ggrothendieck opened this issue · comments
ggrothendieck commented
(1) below works as expected but if we replace data.frame with list giving (2) it gives a different answer. Is this expected?
library(lubridate)
library(magrittr)
library(listcompr)
my_interval = interval(dmy("15/07/2019"), dmy("15/07/2020"))
my_intervals <- rep(my_interval, 3)
# 1
my_intervals %>% {
n <- length(.)
gen.data.frame(data.frame(int1 = .[i], int2 = .[j],
overlaps = int_overlaps(.[1], .[j])), i < j, i = 1:n, j = 1:n)
}
int1 int2 overlaps
## 1 2019-07-15 UTC--2020-07-15 UTC 2019-07-15 UTC--2020-07-15 UTC TRUE
## 2 2019-07-15 UTC--2020-07-15 UTC 2019-07-15 UTC--2020-07-15 UTC TRUE
## 3 2019-07-15 UTC--2020-07-15 UTC 2019-07-15 UTC--2020-07-15 UTC TRUE
# 2 - same except data.frame replaced with list on second last line
my_intervals %>% {
n <- length(.)
gen.data.frame(list(int1 = .[i], int2 = .[j],
overlaps = int_overlaps(.[1], .[j])), i < j, i = 1:n, j = 1:n)
}
## int1 int2 overlaps
## 1 31622400 31622400 TRUE
## 2 31622400 31622400 TRUE
## 3 31622400 31622400 TRUE
Patrick Roocks commented
No this is not intended, internally the as.data.frame
call happens too late... I will fix that soon. Thanks for that finding!
Patrick Roocks commented
Fixed with the last commit.
Now we have:
> library(lubridate)
> library(magrittr)
>
> my_interval = interval(dmy("15/07/2019"), dmy("15/07/2020"))
> my_intervals <- rep(my_interval, 3)
> my_intervals %>% {
+ n <- length(.)
+ gen.data.frame(list(int1 = .[i], int2 = .[j],
+ overlaps = int_overlaps(.[1], .[j])), i < j, i = 1:n, j = 1:n)
+ }
int1 int2 overlaps
1 2019-07-15 UTC--2020-07-15 UTC 2019-07-15 UTC--2020-07-15 UTC TRUE
2 2019-07-15 UTC--2020-07-15 UTC 2019-07-15 UTC--2020-07-15 UTC TRUE
3 2019-07-15 UTC--2020-07-15 UTC 2019-07-15 UTC--2020-07-15 UTC TRUE