Skip to content

extract_r_source fails when knitr pattern chunk.end doesn't match any lines #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hstahl opened this issue Jul 26, 2016 · 2 comments
Closed

Comments

@hstahl
Copy link

hstahl commented Jul 26, 2016

I have an R source file which causes lintr to throw its hands in the air and fail with an error. The problem is in the extract_r_source function.

To reproduce:

lines <- c("# This single comment `r length(x)` with some inline code is enough.\n")
temp <- tempfile(fileext = '.R')
cat(lines, file = temp)
tryCatch(lint(temp, with_defaults()), finally = unlink(temp))
# Error in rep.int(NA_character_, max(ends - 1)) : invalid 'times' value
# In addition: Warning messages:
#1: In max(ends - 1) : no non-missing arguments to max; returning -Inf
#2: In rep.int(NA_character_, max(ends - 1)) :
#   NAs introduced by coercion to integer range

The error is from https://github.com/jimhester/lintr/blob/master/R/extract.R#L17.

If some knitr patterns are found but the chunk.end pattern doesn't end up matching any lines of code, an error is thrown by rep.int since -Inf gets passed as its times parameter. Leading up to the error:

  • pattern is not NULL.
  • ends and starts are integer(0) since no matching lines of code were found by grepl
  • calling max(integer(0) - 1) returns -Inf
  • rep.int(NA_character_, -Inf) throws the error above.
@jsta
Copy link

jsta commented Jun 6, 2017

I am having this problem as well. Did you resolve it on your end @hstahl? What patterns do I need to insert in my chunk?

@jsta
Copy link

jsta commented Jun 6, 2017

I solved this issue by installing the latest dev version from Github (inspired by #228). I suggest that this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants