Search code examples
rpackagelatexdevtoolsroxygen2

I have unicode characters/ latex errors in my documentation causing issues in R CMD check. How do I troubleshoot?


I am building my my first pacakge, and when running R CMD check after devtools::build() I found a bunch of issues with "checking PDF version of the manual." I struggled to find directions on how to troubleshoot so I'm going to ask this question: "How can I identify the problematic text in my .R files that Roxygen uses to make the .Rd files that make up the manual?" and then go ahead an answer in hopes that it is useful to someone else down the line.

I would get a long series of WARNINGS, and the unique components are below:

LaTeX errors when creating PDF version. This typically indicates Rd problems. LaTeX errors found: ! LaTeX Error: Bad math environment delimiter.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ! Package inputenc Error: Unicode character ℓ (U+2113) (inputenc)
not set up for use with LaTeX.

See the inputenc package documentation for explanation. Type H for immediate help.

I thought these were pretty clear: Somewhere I have bad Latex (like a missing curly bracket or dollar sign, a imagine), and also there is some issue with including this unicode character.

My question is, "How do I identify the offending lines?"


Solution

  • Following up on @user2554330's comment. Here's a simple way to check for eventual unicode characters in your functions and documentation:

    # functions
    functions <- list.files(path = './R', all.files = T, recursive = T, full.names = T)
    lapply(X=functions, FUN = tools::showNonASCIIfile)
    
    # documentation
    docs <- list.files(path = './man', all.files = T, recursive = T, full.names = T)
    lapply(X=docs, FUN = tools::showNonASCIIfile)