Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter() on dataframe containing lubridate Interval: corrupt data frame #2221

Closed
otoomet opened this issue Oct 31, 2016 · 2 comments
Closed

Comments

@otoomet
Copy link

otoomet commented Oct 31, 2016

Create a data frame that contains lubridate interval:

dfoo <- data.frame(x=1:5,
       int=lubridate::interval(seq(ISOdate(2000,1,1), ISOdate(2000,1,5), length.out=5),
                               seq(ISOdate(2001,1,1), ISOdate(2001,1,5), length.out=5)))

Now

dfoo[dfoo$x < 4,]

works as expected. However,

dplyr::filter(dfoo, x < 4)

gives warning:

Warning messages:
1: In unclass(e1) + unclass(e2) :
  longer object length is not a multiple of shorter object length
2: In format.data.frame(x, digits = digits, na.encode = FALSE) :
  corrupt data frame: columns will be truncated or padded with NAs

One can also check that the resulting data frame has x of length
3 and int of length 5. Perhaps related to #1366.

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] lubridate_1.6.0 dplyr_0.5.0    

loaded via a namespace (and not attached):
 [1] compiler_3.3.1 lazyeval_0.2.0 R6_2.1.3       assertthat_0.1
 [5] magrittr_1.5   DBI_0.5-1      tools_3.3.1    tibble_1.2    
 [9] Rcpp_0.12.3    stringi_1.0-1  stringr_1.0.0 
@otoomet otoomet changed the title filter() on dataframe containing lubridate Interval: get length wrong filter() on dataframe containing lubridate Interval: corrupt data frame Oct 31, 2016
@jmorten
Copy link

jmorten commented Oct 31, 2016

try:

dfoo <- data_frame(x=1:5,
       int=lubridate::interval(seq(ISOdate(2000,1,1), ISOdate(2000,1,5), length.out=5),
                               seq(ISOdate(2001,1,1), ISOdate(2001,1,5), length.out=5)))

@krlmlr
Copy link
Member

krlmlr commented Nov 7, 2016

Related: #1581. There is little support for vector-like objects with a nonstandard storage format (such as POSIXlt and lubridate::interval). See also r-lib/vctrs#27.

@hadley hadley closed this as completed Jan 31, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants