Skip to content

[R-pkg-devel] Unexpected symbol when checking package examples

7 messages · Jared Knowles, Peter Dalgaard, Duncan Murdoch

#
Hi!

I have a bit of a weird issue when I'm trying to check my package merTools
(source repo available here: https://github.com/jknowles/merTools

On Windows and Linux builds for R-release and R-devel, when R CMD CHECK
checks examples, it returns the following error below:

Warning: parse error in file 'merTools-Ex.R':
1: unexpected symbol
117: cleanEx()
118: nameEx


Upon inspecting the example file generated by R CMD CHECK (mertools-Ex.R) -
it contains only valid R code. I can run it line by line or source the
whole file in R without any errors. But, during the check process, this
error occurs.

The functions cleanEx() and nameEx() appear to be created as part of the
checking process.

I have not changed the examples in the code since the last time I ran R CMD
CHECK so I am quite confident that the example code for all functions is
valid R code.

Any ideas on what might be the source of this problem?

               Thanks!
                 Jared



Jared Knowles
President, Civilytics Consulting LLC
www.jaredknowles.com
#
Not just a capitalization issue (mertools vs. merTools)?

Barring that, maybe locale trouble? Can you also do things like

LC_ALL=C R < merTools-Ex.R

?

Also, check for lines starting with "else" (I think you shouldn't be able to run it line-by-line if that was the issue, though).

-pd

  
    
#
On 11/11/2018 3:39 PM, Jared Knowles wrote:
I also get this error on MacOS.
The problem is in the REimpact help file.  It contains this:

zed3 <- REimpact(g1, newdata = InstEval[9:12, ], groupFctr = "d", breaks 
= 5,

and there's no closing paren.

This is in a \donttest section of the examples, so it gets deleted when 
running the examples, and that's the version of merTools-Ex.R that is 
left at the end.  But the warning happened in a different test,

* checking for unstated dependencies in examples ... WARNING
Warning: parse error in file 'merTools-Ex.R':
1: unexpected symbol
118: cleanEx()
119: nameEx
      ^

and it is based on a different version of that file that doesn't omit 
the \donttest section.

This is arguably an R bug:  the line numbers are misleading, since they 
refer to a version of the file that no longer exists.  Perhaps when you 
say \donttest, no tests should be done.

Duncan Murdoch
#
On 11/11/2018 6:53 PM, Duncan Murdoch wrote:
Cancel that last sentence:  if you run "example(REimpact)", you get a 
syntax error message, because \donttest is not the same as \dontrun.  So 
this has to be fixed in the original file.

But the first part is still right:  you shouldn't say the problem is on 
line 119 of 'merTools-Ex.R', and then rewrite the file so that line 
isn't there any more.

Duncan Murdoch
#
On 11/11/2018 7:01 PM, Duncan Murdoch wrote:
I have submitted a bug report 
(https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17501) about this.

Duncan Murdoch
#
Thank you so much for the help!

The origin of this mistake was mine - I forgot a ' following a # in my
roxygen example code - which meant roxygen ignored the closing parens on
the next line. (See example)

\donttest{
#' # You can also pass additional arguments to predictInterval through
REimpact
#' g1 <- lmer(y ~ lectage + studage + (1|d) + (1|s), data=InstEval)
#' zed <- REimpact(g1, newdata = InstEval[9:12, ], groupFctr = "d", n.sims
= 50,
#'                 include.resid.var = TRUE)
#' zed2 <- REimpact(g1, newdata = InstEval[9:12, ], groupFctr = "s", n.sims
= 50,
#'                  include.resid.var = TRUE)
#' zed3 <- REimpact(g1, newdata = InstEval[9:12, ], groupFctr = "d", breaks
= 5,
#                 n.sims = 50, include.resid.var = TRUE)
#' }

Thanks everyone for the help. I never would have found this mistake without
this list.

         Jared


On Sun, Nov 11, 2018 at 6:53 PM Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:

  
  
#
On 12/11/2018 7:56 AM, Jared Knowles wrote:
Perhaps roxygen should try parsing the code it inserts as examples.  It 
can probably give a better error message than R could, since it knows 
which .R file it's looking at when the problem happens.

Duncan Murdoch