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

labelled class clashes with Hmisc #329

Closed
ewenharrison opened this Issue Dec 22, 2017 · 8 comments

Comments

Projects
None yet
5 participants
@ewenharrison
Copy link

ewenharrison commented Dec 22, 2017

#86

I'm still having issues with this. I have a data.frame with variables of class labelled which I would rather keep. There is still a haven conflict. Any ideas appreciated. I'm not using haven but it loads with tidyverse hence issue.

# Simple linear regression
data(mtcars)
lm(mpg~cyl, data=mtcars) # Works as expected

# Add attribute
class(mtcars$mpg) = c("labelled",class(mtcars$mpg))
lm(mpg~cyl, data=mtcars) # Works as expected

library(haven)
lm(mpg~cyl, data=mtcars) #Error: `x` and `labels` must be same type
@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 7, 2018

Where are the labelled variables coming from?

You can't generally expect to add an arbitrary class to variables and expect things to work, but maybe you just did that to minimise the reprex?

@hadley hadley added the reprex label Jan 7, 2018

@ewenharrison

This comment has been minimized.

Copy link

ewenharrison commented Jan 7, 2018

Hmisc::label()

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

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jan 7, 2018

I don't think there's a great short term fix for this - the right thing to do is to make the class name more unique (i.e. haven_labelled), but that is likely to break downstream packages. I'll explore this next time we do a major release.

@hadley hadley changed the title Error: `x` and `labels` must be same type reopened labelled class clashes with Hmisc Jan 16, 2018

@harlananelson

This comment has been minimized.

Copy link

harlananelson commented Feb 2, 2018

From lrm examples.

cholesterol    <- rnorm(n, 200, 25)
label(cholesterol)    <- 'Total Cholesterol'
ch <- cut2(cholesterol, g=40, levels.mean=TRUE) # use mean values in intervals

Same error.

@ewenharrison

This comment was marked as resolved.

Copy link

ewenharrison commented May 18, 2018

I think this issue is resolved? I am no longer getting the issue.

@huftis

This comment was marked as resolved.

Copy link
Contributor

huftis commented May 18, 2018

I still get the same error message, @ewenharrison. Here’s a reprex:

library(Hmisc)
#> Lastar nødvendig pakke: lattice
#> Lastar nødvendig pakke: survival
#> Lastar nødvendig pakke: Formula
#> Lastar nødvendig pakke: ggplot2
#> 
#> Koplar til pakke: 'Hmisc'
#> De følgende objekter er maskerede fra 'package:base':
#> 
#>     format.pval, units
cholesterol <- rnorm(10, 200, 25)
label(cholesterol) <- 'Total Cholesterol'
cholesterol
#> Total Cholesterol 
#>  [1] 210.5846 213.7192 186.3711 200.8709 219.1156 194.6663 202.2819
#>  [8] 179.0255 217.5504 193.4632
ch <- cut2(cholesterol, g = 4, levels.mean = TRUE)

library(haven)
cholesterol
#> <Labelled double>
#> Error: `x` and `labels` must be same type
ch <- cut2(cholesterol, g = 4, levels.mean = TRUE)
#> Error: `x` and `labels` must be same type
@ewenharrison

This comment was marked as resolved.

Copy link

ewenharrison commented May 18, 2018

Apologies, me too with that reprex.

@gforge

This comment has been minimized.

Copy link

gforge commented May 20, 2018

This bug can be tricky, some packages depend on other packages that force-load haven. I've recently debugged: AER -> car -> rio -> haven

I think this is something that the CRAN group should look into - each package should define the S3 classes and state which S3 classes it imports. Until then, please consider fixing this. I just wasted about 1-2 hours...

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