0
votes

I am a latex newbee. I properly installed MikTeX 2.9, GhostScript, GSView, TeXnicCenter, and made the settings properly.

My package (named "mypackage") passed package check
via
From R console: devtools::check("C:/Users/User/Documents/Revolution/mypackage")
From DOS command prompt: R CMD check mypackage
without any problem, and I obtained mypackage.PDF files automatically eventually.

I decided to produce mathematical expressions, e.g.,

enter image description here

in the resultant .PDF file. So, I added the following latex expressions in the line in .R file:

#' @param max selected ...The default is Schwert's approximation: \eqn{\lfloor 12(length(t) \over 100)^{\sfrac{1}{4}} \rfloor}

I roxygenized and triggered the above package-checks once more. This time, in the package check, I get the following error (in Command Prompt):

* checking PDF version of manual ...Warning: running command '"C:/Revolution/R-Enterprise-7.3/R-3.1.1/bin/x64/Rcmd.exe" Rd2pdf  --batch --no-preview --build-dir
="C:/Users/User/AppData/Local/Temp/RtmpysnRGn/Rd2pdf1b3050f426ea" --no-clean -o mypackage-manual.pdf  

"C:/Users/User/Documents/Revolution/mypackage.Rcheck/mypackage"' had status 1
 WARNING LaTeX errors when creating PDF version. This typically indicates Rd problems. LaTeX errors found: ! Undefined control sequence.
<argument> ...oor 12(length(t) \over 100)^{\sfrac
    {1}{4}} \rfloor
l.67 ...th(t) \over 100)^{\sfrac{1}{4}} \rfloor}{}

checking PDF version of manual without hyperrefs or index ...Warning: running command '"C:/Revolution/R-Enterprise-7.3/R-3.1.1/bin/x64/Rcmd.exe" Rd2pdf  --bat
ch --no-preview --build-dir="C:/Users/User/AppData/Local/Temp/RtmpysnRGn/Rd2pdf1b3069b07b94" --no-clean --no-index -o  mypackage-manual.pdf  

C:/Users/User/Documents/Revolution/mypackage.Rcheck/mypackage' had status 1 ERROR

What I did: I analyzed the similar error in SOF, but could not figure out what is going wrong. I am not sure from where the error occured: my latex syntax or something in R.

I would greatly appreciate any help.

Edit (Complete preamble upon Werner's remark; after the below solution is imposed):

#' adfcs
#'
#' Augmented Dickey-Fuller test that uses common (sub-)sample for all of the lags when a selected max order is given to find optimal minimal lag order of the autoregressive process.
#'
#' Augmented Dickey-Fuller test (for unit root testing) that uses common (sub-)sample for all of the lags when a selected max order is given to find optimal minimal lag order of the autoregressive process. 
#' The test is based on J.G. McKinnons' numerical distribution functions. 
#' MacKinnon, J.G. (1996); Numerical distribution functions for unit root and cointegration tests, J of Applied Econometrics 11, p. 601 618.
#' The default value of max is Schwert's approximation (Schwert, G.W. (1989). Tests for Unit-Roots: A Monte Carlo investigation. Journal of Business and Economic Statistics 7, 147-159.) 
#' Usage: adfcs(t, max = floor(12*(length(t)/100)^(1/4)), type = c("c")). I thank Fabian Scheipl, Dept. of Statistics, LMU Munich for his helpful suggestions during the construction of adfcs. 
#' When data frame is supplied for the parameter t, specify the column of the variable for which the ADF test is wanted .
#'
#' @param t a numeric vector or time series object whose stationarity is examined
#' @param max selected max lag order to find optimal minimal lag order for the autoregressive process in ADF test. The default is Schwert's approximation: \eqn{\left\|12\left(\frac{length(t)}{100}\right)^{1/4}\right\|}
#' @param type a character string describing the type of the unit root  regression. Valid choices are "nc" for a regression  with no intercept (constant) nor time trend, and "c"  for a regression with an intercept (constant) but no time  trend, "ct" for a regression with an intercept  (constant) and a time trend. The default is "c".
#' @return Augmented Dickey-Fuller test that uses common sample for all of the lags.
#' @author Erdogan Cevher erdogancevher@@gmail.com
#' @seealso \code{\link{VARomlop}}
#' @examples
#' ## ADF test for the 1st variable in granger.df, max length is that of Schwert's approximation (default).
#' # adfcs(granger.df[,1])
#' ## ADF test for the 3rd variable in granger.df, max length is 10.
#' # adfcs(granger.df[,3], 10)
#' @importFrom fUnitRoots unitrootTest
#' @export
adfcs <- function(...
1
You should probably include the xfrac package in your preamble in order to use \sfrac. However, I'd suggest just using 1/4.Werner
@Werner To add package to the preamble, I took hint from link . I added #' header-includes: #' - \usepackage{xfrac} to the .R file to include xfrac package to use \sfrac. I triggered R CMD check mypackage. An error appeared: * checking whether package 'mypackage' can be installed ... WARNING Found the following significant warnings: Warning: C:/Users/User/Documents/Revolution/mypackage/man/adfcs.Rd:31: unknown macro '\usepackage'. It seems I cannot achieve how to include a TeX package to R's preamble.Erdogan CEVHER
So you're using Rmarkdown and compiling to PDF? You should really provide the community with a complete example of your code, and not just fragmented snippets.Werner
@Werner, I added the complete preamble of the .R file. AFAIK, I don't use Rmarkdown. I use roxygen2 package. #' tags are required tags for the roxygen2 package. roxygen2 produces .Rd files from .R files automatically (upon roxygenize("mypackage")). From there, from command prompt, via R CMD check mypackge, I obtain the .PDF files automatically (I installed MikTex and TexNicCenter; GScript; GSview as well; all properly set).Erdogan CEVHER

1 Answers

0
votes

1. I found a free online/real-time/WYSIWYG latex converter: https://www.codecogs.com/latex/eqneditor.php

In this website; by trial and error, I discovered the latex syntax for Schwertz's formula:

\left\|12\left(\frac{length(t)}{100}\right)^{1/4}\right\|

(I suggest separating latex tags from each other via spaces (when clicking the above math'l symbols) to discover/learn the latex tags' jobs further.) Deleting all the spaces between tags did not affect the resultant math'l expression.

2. Then, I replaced the codecogs's above latex code within \eqn{...} tag:

#' @param max selected ...The default is Schwert's approximation: \eqn{\left\|12\left(\frac{length(t)}{100}\right)^{1/4}\right\|}

I did not add anything to the preamble in the .R file.

3. Then, I re-triggered R CMD check mypackage from DOS Command Prompt.

This time, package was checked without any problem. I obtained .PDF file in which above .jpg's content is mutatis mutandis shown.

(If I can perform Werner's solution, I'll put it here as well)