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

labelled class clashes with Hmisc #329

Closed
ewenharrison opened this issue Dec 22, 2017 · 9 comments
Closed

labelled class clashes with Hmisc #329

ewenharrison opened this issue Dec 22, 2017 · 9 comments
Labels

Comments

@ewenharrison
Copy link

@ewenharrison 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
Copy link
Member

@hadley 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
Copy link
Author

@ewenharrison ewenharrison commented Jan 7, 2018

Hmisc::label()

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

@hadley 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
Copy link

@harlananelson 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 has been hidden.

@huftis

This comment has been hidden.

@ewenharrison

This comment has been hidden.

@gforge
Copy link

@gforge 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...

@lock
Copy link

@lock lock bot commented Feb 24, 2019

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 Feb 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants