3

I've recently made a series of edits to source and documentation code to an R package, and when I attempt to render documentation (using devtools::check_man()) I receive the error:

'DESCRIPTION' file has an 'Encoding' field and re-encoding is not possible

As far as I can tell, this indicates that I have included some non-ASCII characters somewhere in the source code of my package.

How can I track down the problematic characters?

I've tried using RStudio's "find in files" with the regular expression [^\x00-\x7F] (per (grep) Regex to match non-ASCII characters?), but this matches almost every line of my code.

slava-kohut suggests (in comments)

lapply(list.files(include.dirs=FALSE, full.names=TRUE, no..=TRUE), 
       tools::showNonASCIIfile)

This finds a non-ASCII character in a file that's included in .Rbuildignore, and then throws the error

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : cannot open file './data': Permission denied
Martin Smith
  • 3,687
  • 1
  • 24
  • 51
  • 7
    Have you tried `tools::showNonASCII` and `tools::showNonASCIIfile`? – slava-kohut Sep 23 '19 at 16:45
  • Thanks for the suggestion – the problem is that there are a lot of files that could potentially harbour the errant character. It will take a long time to enter their names manually. – Martin Smith Sep 23 '19 at 16:47
  • 2
    Perhaps, you could test all your `Rd` files using a loop based off `list.files` and `tools::showNonASCIIfile`. – slava-kohut Sep 23 '19 at 16:49

0 Answers0