Skip to content

[R-pkg-devel] Encoding problem

3 messages · David Scott, Thierry Onkelinx

#
I am trying to add a vignette to xtable showing how to incorporate some 
Chinese characters following an enquiry from a user.

I can create the vignette satisfactorily just processing the knitr file 
normally, with the resulting pdf displaying Chinese characters in the R 
code and also as headings when I produce a table. However when I try to 
build the package with the vignette included, I get:

* creating vignettes ...Warning: running command 
'"C:/PROGRA~1/R/R-33~1.2/bin/x64/Rscript" --vanilla
  ERROR
Error: Vignette 'ChineseCharacters.Rnw' is non-ASCII but has no declared 
encoding
Execution halted
make: *** [build] Error 1

I updated R to 3.3.2 and Rtools to 33 before running the build.

The vignette starts as follows:

%\VignetteIndexEntry{xtable Chinese Characters}
%\VignetteDepends{xtable}
%\VignetteKeywords{LaTeX, HTML, table}
%\VignettePackage{xtable}
% !Rnw weave = knitr
% \VignetteEngine{knitr::knitr}
%!\VignetteEncoding{UTF-8}
%**************************************************************************
\documentclass{ctexart}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{hyperref}
\usepackage{inputenx}

The section of the file which is not ASCII is:

<<preparedata>>=
### Prepare data
library(knitr)
library(xtable)

tbl <- data.frame(positivePairs = 0, negativePairs = 0,
                   avePositiveSpread = NA,
                   aveNegativeSpread = NA,
                   PnL = 435, sumPnL = 144358.7)
names(tbl) <- c("????????", "????????", "????????????????",
                 "????????????????", "????????", "????????")
@

I am a bit of a novice at encodings, and know nothing about Chinese 
characters so any advice is welcome.

David Scott
1 day later
#
Dear David,

Have you tried removing the exclamation mark in %!\VignetteEncoding{UTF-8}?
I think it should be %\VignetteEncoding{UTF-8}

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2017-01-29 13:40 GMT+01:00 David Scott <d.scott at auckland.ac.nz>:

  
  
#
Thanks Thierry, that indeed was the problem.

I am not sure who to advise to correct the documentation in Writing R 
Extensions though because I was following the instructions there:

"... the encoding may be declared using a comment like

%!\VignetteEncoding{UTF-8}

If the encoding is UTF-8, this can also be declared using the declaration

%!\SweaveUTF8"


The same instruction appears in all the versions of WRE that I checked, 
HTML and PDF, R-release, R-patched and R-devel.

I have copied in Duncan and Martin in the expectation they might ensure 
a correction.

David
On 31/01/2017 4:10 a.m., Thierry Onkelinx wrote: