When I want to label the variables of my dataframe using german umlaute or superscript etc... with this code everything works fine:
library(dplyr)
library(Hmisc)
## with this code everthing works fine
# dataframe
colnamesiris <- c("a", "b", "c", "d")
iris_test <- iris %>%
select(2:5) %>%
setNames(colnamesiris)
# defining labels
df_test_labels <- c(
a = "Fake1 [cm²]",
b = "Fake2 ä",
c = "Fake3 Ö",
d = "üüü³²³")
# assign labels to dataframe (iris_test)
iris_test <- Hmisc::upData(iris_test, labels = df_test_labels)
View(iris_test)
- In order to clean up workflow I split this code into two files 1. analysis.R with sourcing the second file containing the label definitions 2. df_test_labels.R (vector of label definitions). In this case the labels do not appear appropriate.
- analysis.R
library(dplyr)
library(Hmisc)
## with this code everthing works fine
# dataframe
colnamesiris <- c("a", "b", "c", "d")
iris_test <- iris %>%
select(2:5) %>%
setNames(colnamesiris)
# assign labels to dataframe (iris_test)
source("./df_test_labels.R") # vector for labels
iris_test <- Hmisc::upData(iris_test, labels = df_test_labels)
View(iris_test)
-
- df_test_labels.R
# defining labels
df_test_labels <- c(
a = "Fake1 [cm²]",
b = "Fake2 ä",
c = "Fake3 Ö",
d = "üüü³²³")
- I found out that this behavior occurs only when
iris_test <- Hmisc::upData(iris_test, labels = df_test_labels)
is not in the same script with the definition of the variable labels. Can someone explain why this is occurring? Thank you in advance.