[R-pkg-devel] Conversion failure in 'mbcsToSbcs'

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Fri Nov 17 16:55:57 CET 2023


Hello!

В Fri, 17 Nov 2023 14:16:27 +0000
Package Maintainer <ggenealogypackage using gmail.com> пишет:

> 2) set_null_device("cairo") to the vignettes/ggenealogy.Rnw file (this
> gives me a "could not find function "set_null_device"" ERROR)

I don't think this function from the cowplot package would have helped.
You are compiling a LaTeX vignette, so you need to produce a PDF plot
to include in the rendered PDF vignette.

> 1) pdf.options(encoding='ISOLatin2.enc') to the
> vignettes/ggenealogy.Rnw file

Something like this should help. Here's how I can reproduce the problem
on latest R-devel:

Sys.setenv('_R_CHECK_MBCS_CONVERSION_FAILURE_' = 'TRUE')
pdf()
graphics::strwidth('Lubomír Kubáček', "inches")
# Error in graphics::strwidth("Lubomír Kubáček", "inches") :
#   conversion failure on 'Lubomír Kubáček' in 'mbcsToSbcs': for í
#   (U+00ED)

Notably, the error is absent if I either call
pdf.options(encoding='ISOLatin2.enc') before pdf() or replace pdf()
with the better-Unicode-equipped cairo_pdf().

As a workaround, you could use the latter device in your vignette by
following section "Custom Graphics Devices" of help(RweaveLatex) (or
section 4.1.5 "Graphics devices" of the Sweave vignette):

<<results=hide,echo=FALSE>>=
my.Swd <- function(name, width, height, ...)
 grDevices::cairo_pdf(
  filename = paste(name, "pdf", sep = "."),
  width = width, height = height
 )
@
\SweaveOpts{grdevice=my.Swd,pdf=FALSE}

With this in the document, the following chunk doesn't crash
_R_CHECK_MBCS_CONVERSION_FAILURE_=TRUE R-devel CMD Sweave:

<<fig=TRUE>>=
# NB: fig=TRUE must be set, otherwise R calls pdf() with default options
graphics::strwidth('Lubomír Kubáček', "inches")
@

So why doesn't it help to call pdf.options() in a Sweave chunk? My
guess is that's too late for Sweave to pick it up by the time it's
weaving a vignette, but RweaveLatex presents an alternative way of
setting the option:

\SweaveOpts{pdf.encoding = ISOLatin2.enc}

With this in the vignette, my previous example also avoids the crash.

Good luck!

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list