Comments (5)
I just submitted an update to CRAN, and this resolved issue should be in the official CRAN release.
from sjlabelled.
Just following up about this after a while. I'd like to use the tool more in my workflow, but as it stands I'm just having to set things up manually.
I still don't understand the seemingly inconsistent behavior when labeling numeric vs. character data types. Looking at the code this behavior appears to be intentional, with the linked section doing the flip if things match (i.e., string data is given string labels).
If there's a mismatch because the labels are given numeric elements with string names, it ignores those and throws a warning, like so:
example <- sample(c("one", "two", "three", "four"), 40, replace = TRUE)
example <- set_labels(dummy, labels = c("one" = 1 , "two" = 2, "three" = 3 , "four" = 3))
example # unlabelled
However, a labels
argument structured like the above would already be improper based on the guidance in the help docs for set_labels
.
In fact, it even looks like a similar mistake would be fixed if it were made when labeling a numeric vector, i.e. here
Is there a purpose to this behavior I'm not understanding? Perhaps something to do with Haven, etc.?
from sjlabelled.
I think there must have been a reason to do this, but I can't remember. I changed the behaviour, so it is now in line with the default haven behaviour:
charvec <- sjlabelled::set_labels(
c("one", "two", "three", "four"),
labels = c(a = "one", b = "two", c = "three", d = "four")
)
charvec2 <- haven::labelled(
c("one", "two", "three", "four"),
labels = c(a = "one", b = "two", c = "three", d = "four")
)
charvec
#> [1] "one" "two" "three" "four"
#> attr(,"labels")
#> a b c d
#> "one" "two" "three" "four"
charvec2
#> <labelled<character>[4]>
#> [1] one two three four
#>
#> Labels:
#> value label
#> one a
#> two b
#> three c
#> four d
sjlabelled::get_labels(charvec, value = "p")
#> [1] "[four] d" "[one] a" "[three] c" "[two] b"
sjlabelled::get_labels(charvec2, value = "p")
#> [1] "[four] d" "[one] a" "[three] c" "[two] b"
Created on 2021-05-11 by the reprex package (v2.0.0)
from sjlabelled.
Excellent, thanks for your help on this.
And thanks for all your work on this package overall!
from sjlabelled.
Just a small follow-up on this--Is there a plan to release a new version of the package CRAN any time soon? Just asking so I can plan--much of my work is done on a managed server, and the policy is generally only to use official CRAN packages.
from sjlabelled.
Related Issues (20)
- `as_label` does not work for a variable with on NAs
- as_labeld(data,drop.na=FALSE) changed from version 1.1.3 to version 1.1.6, intended? HOT 1
- as_labelled missing additional classes used by haven
- expecting a sjlabelled cheat sheet
- Please consider set F as default for as.num and atomic.to.fac HOT 2
- label_to_colnames additional arguments for variable selection HOT 2
- sjlabelled::write_spss(): Codes change from R to SPSS HOT 1
- write_spss not working with integer vectors HOT 12
- R session aborted when trying to import a .dta file HOT 1
- add `ordered` option to `as_label()` HOT 5
- var_labels() function won't work with x as a variable name
- Suggestion for using formats as an attribute
- custom attributes for values and variables HOT 1
- Duplicate value labels in `tab_stackfreq` when using `sjlabelled::as_label(keep.labels = TRUE)` HOT 1
- the argument ref.lvl in sjmisc::to_factor() not working HOT 4
- Problem with tidy-select where() in add-labels()
- how to recode different 'types' of missing in R from a .dta file
- Variable Labels and Date Columns
- set_labels() not working HOT 1
- set_label() forced variables to characters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sjlabelled.