Skip to content

READ_SAS() doesn't read label when variable class is (“POSIXct” “POSIXt”) #624

Closed

Description

Hi,

currently I’m working with haven.read_sas() function. I’ve probably found a bug when I have variable with label in dataset which has class is (“POSIXct” “POSIXlt”).

Usually variables have two attributes: label and class. But in case when class is (“POSIXct” “POSIXt”) there is three attributes: timezone, label, class.

I resolved this issue by manually change variable attributes order so that label always will be on the first place.

In my opinion, it can be useful to adjust on the haven.read_sas() function’s code.

Here is my MWE / MRE:

---
author: ashemiak
date: 2021-08-01
output: "reprex::reprex\\_document"
title: grave-cobra\_reprex.R
---

``` r
library(data.table)
#> Warning: package 'data.table' was built under R version 4.0.5
library(haven)
#> Warning: package 'haven' was built under R version 4.0.5
library(reprex)
#> Warning: package 'reprex' was built under R version 4.0.5

aaa <- data.table(datetime = c(1550053200, 1553162400, 1556616900, 1561716300, 1570010100, 1570528620, 1574763600, 1577440800, 1580722800, 1542191700, 1543831080),
                  date = c(17940, 17976, 18016, 18075, 18171, 18177, 18226, 18257, 18295, 17849, 17868))

aaa$datetime <- as.POSIXct(aaa$datetime, origin = '1970-01-01', tz = 'GMT')
aaa$date <- as.Date(aaa$date, tryFormats = '%Y-%m-%d', origin = '1970-01-01')

attributes(aaa$datetime)$label <- 'example datetime'
attributes(aaa$date)$label <- 'example date'

write_sas(aaa, 'C:/Users/ashemiak/Desktop/bbb.sas7bdat')
get_bbb <- read_sas('C:/Users/ashemiak/Desktop/bbb.sas7bdat')

Created on 2021-08-01 by the reprex package (v2.0.0)

``` Here is initial dataset AAA:

aaa

Here is dataset GET_BBB after read_sas() execution:

image

Here is what happens with attributes:

image

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

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions