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

Xpt date handling #313

Closed
jetravis opened this Issue Sep 21, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@jetravis
Copy link

jetravis commented Sep 21, 2017

read_xpt reads variables stored in date and datetime format as doubles.

http://rpubs.com/jetravis/haven_xpt_date_test

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 7, 2018

Can you please make an inline reprex? There's no need to include sessionInfo()

@hadley hadley added the reprex label Jan 7, 2018

@jetravis

This comment has been minimized.

Copy link

jetravis commented Jan 7, 2018

library(lubridate)                                                                                                 
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date
library(tibble)                                                                                                    
library(haven)                                                                                                     
                                                                                                                   
xptTest <- tibble(dates=ymd("2017-01-01","2017-02-02"), datetimes = ymd_hm("2017-01-01 10:00", "2017-02-02 11:00"))
write_xpt(xptTest, "test.xpt",version = 5)                                                                         
read_xpt("test.xpt")                                                                                               
#> # A tibble: 2 x 2
#>   dates   datetime
#>   <dbl>      <dbl>
#> 1 17167 1483264800
#> 2 17199 1486033200
@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 7, 2018

GitHub issues use markdown and they're much easier to read if you learn a little bit about it. The most important thing is to put your R code inside a block that starts with ```R and ends with ```. I've done that for you here, but I'd really appreciate it if you would format it yourself in the future.

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 7, 2018

More minimal reprex:

library(haven)
x <- as.Date("2018-01-01")
df <- data.frame(date = x, datetime = as.POSIXct(x))

path <- tempfile()
write_xpt(df, path, version = 5)
read_xpt(path)
#> # A tibble: 1 x 2
#>    date   datetime
#>   <dbl>      <dbl>
#> 1 17532 1514764800

Created on 2018-01-07 by the reprex package
(0.1.1.9000)
.

@hadley hadley added feature and removed reprex labels Jan 7, 2018

@jetravis

This comment has been minimized.

Copy link

jetravis commented Jan 7, 2018

Sorry, still new at this.

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 16, 2018

The root cause appears to be that Rf_lengthgets() strips attributes.

@hadley hadley closed this in d722c31 Jan 16, 2018

@lock

This comment has been minimized.

Copy link

lock bot commented Jul 15, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jul 15, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.