0

I'm using the picker() function to manipulate a ggplot2 line graph. I have strings with accented characters in the list given to picker. When I select a string with accented characters, ggplot() returns

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

The sample code works fine:

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

However, if I adapt the code as follows, picker() fails:

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) gives this:

 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>"

When "Employé" is selected, NULL is passed by picker() to barplot() and I get the following errors:

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

Any idea of what is wrong?

tonytonov
  • 25,060
  • 16
  • 82
  • 98
jplcva
  • 1
  • 1

1 Answers1

0

The problem is solved by looking at this question, and adjusting my system preferences with this command: system("defaults write org.R-project.R force.LANG en_US.UTF-8")

Community
  • 1
  • 1
jplcva
  • 1
  • 1