picker()来自带有重音字符的操纵包

时间:2014-08-18 09:50:37

标签: r utf-8 non-ascii-characters

我正在使用picker()函数来操作ggplot2折线图。我在给予选择器的列表中有带重音字符的字符串。当我选择带有重音字符的字符串时,ggplot()返回

Error in plot.window(xlim, ylim, log = log, ...).

示例代码工作正常:

manipulate(
    barplot(as.matrix(longley[,factor]), 
            beside = TRUE, main = factor),
    factor = picker("GNP", "Unemployed", "Employed"))

但是,如果我按如下方式修改代码,picker()将失败:

library(manipulate)

dflongley <- longley
colnames(dflongley)[7] <- "Employé"
Encoding(colnames(dflongley)) <- "UTF-8"

x <- c("GNP", "Unemployed", "Employé")
Encoding(x) <- "UTF-8"

manipulate(
    barplot(as.matrix(dflongley[,factor]), 
            beside = TRUE, main = factor),
    factor = picker(as.list(x)))

head(dflongley, 1)给出了这个:

 GNP.deflator     GNP Unemployed Armed.Forces Population Year Employ<U+00E9>
 1947           83 234.289      235.6          159    107.608 1947         60.323

X:

[1] "GNP"          "Unemployed"   "Employ<U+00E9>"

选择“Employé”时,picker()将{NULL}传递给barplot(),我收到以下错误:

Error in plot.window(xlim, ylim, log = log, ...) : 
  need finite 'xlim' values
In addition: Warning messages:
1: In min(w.l) : no non-missing arguments to min; returning Inf
2: In max(w.r) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf

知道什么是错的?

1 个答案:

答案 0 :(得分:0)

通过查看this question并使用此命令调整系统首选项来解决问题:system("defaults write org.R-project.R force.LANG en_US.UTF-8")