Hey folks, I'm currently helping a collaborator update their function documentation in the R package 'IndependenceTests'. I've recently migrated the old documention to roxygen2 for better NAMESPACE management.
In one example for the dependogram
function, the'%in%' operator is used.
#' n <- 100
#' W <- sample(x = 1:8, size = n, TRUE)
#' X1 <- W %in% c(1, 2, 3, 5)
#' X2 <- W %in% c(1, 2, 4, 6)
#' X3 <- W %in% c(1, 3, 4, 7)
#' X4 <- W %in% c(2, 3, 4, 8)
#' X <- cbind(X1, X2, X3, X4)
#' dependogram(X, vecd.or.p = c(1, 1, 1, 1), N = 10, B = 20, alpha = 0.05,
#' display = TRUE, graphics = TRUE)
document()
executes successfully and calling the .Rd of the function
Unfortunately, check()
or R CMD CHECK complains giving me this ERROR
❯ checking for unstated dependencies in examples ... ERROR
Warning: parse error in file 'lines':
9: unexpected '\\'
174: W <- sample(1:8, n, replace = TRUE)
175: X1 <- W \
^
This is the corresponding section of the example in the dependogram.Rd
n <- 100
W <- sample(x = 1:8, size = n, TRUE)
X1 <- W \%in\% c(1, 2, 3, 5)
X2 <- W \%in\% c(1, 2, 4, 6)
X3 <- W \%in\% c(1, 3, 4, 7)
X4 <- W \%in\% c(2, 3, 4, 8)
X <- cbind(X1, X2, X3, X4)
I can see the % is being escaped but I couldn't find the '\' the error is referring to.
I tried to workaround the problem by using markdown syntax and R chunks following the R packages book, but with no success.
Adding @md in my function file and placing the problem code into ```{r} chunks, like so:
#' ```{r}
#' n <- 100
#' W <- sample(x = 1:8, size = n, TRUE)
#' X1 <- W %in% c(1, 2, 3, 5)
#' X2 <- W %in% c(1, 2, 4, 6)
#' X3 <- W %in% c(1, 3, 4, 7)
#' X4 <- W %in% c(2, 3, 4, 8)
#' X <- cbind(X1, X2, X3, X4)
#' dependogram(X, vecd.or.p = c(1, 1, 1, 1), N = 10, B = 20, alpha = 0.05,
#' display = TRUE, graphics = TRUE)
#'```
resulted in another familiar RMD error:
❯ checking for unstated dependencies in examples ... ERROR
Warning: parse error in file 'lines':
attempt to use zero-length variable name
I also tried the less recommended option of placing the example in a ```R chunk
but I get the same attempt to use zero-length variable name
error.
I even had a look at the dplyr repo's across.R to see if I have got the formatting of the chunks right!
I am perplexed and a bit lost! I am tempted to comment out the examples.
Would really appreciate your suggestions and advice