Skip to content
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

Bug in as.data.frame.lints() [patch] #179

Closed
fangly opened this issue Oct 20, 2016 · 2 comments
Closed

Bug in as.data.frame.lints() [patch] #179

fangly opened this issue Oct 20, 2016 · 2 comments

Comments

@fangly
Copy link
Contributor

fangly commented Oct 20, 2016

Still following the tutorial at https://cran.r-project.org/web/packages/lintr/vignettes/creating_linters.html

A Lint object is created as:

Lint(
  filename = source_file$filename,
  line_number = parsed$line1,
  column_number = parsed$col1,
  type = "style",
  message = "Use <-, not =, for assignment.",
  line = source_file$lines[parsed$line1]
  )

According to the help page for Lint, the linter parameter appears optional:

Lint(filename, line_number = 1L, column_number = NULL, type = c("style",
  "warning", "error"), message = "", line = "", ranges = NULL,
  linter = NULL)

All good then!

Except that further down the line when executing lint() with a small test case, I get an error message:

 Error in vapply(x, `[[`, character(1), "linter") : 
  values must be length 1,
 but FUN(X[[1]]) result is length 0 
10. vapply(x, `[[`, character(1), "linter") 
9. data.frame(filename = vapply(x, `[[`, character(1), "filename"), 
    line_number = vapply(x, `[[`, numeric(1), "line_number"), 
    column_number = vapply(x, `[[`, numeric(1), "column_number"), 
    type = vapply(x, `[[`, character(1), "type"), message = vapply(x,  ... 
8. as.data.frame.lints(lints) 
7. as.data.frame(lints) 
6. exclude(lints, ...) 
5. lint("./R/try_style.R", linters = semicolon_linter) at debugme.R#2
4. eval(substitute(expr), envir, enclos) 
3. evalq({
    library(lintr)
    lint("./R/try_style.R", linters = semicolon_linter)
}, envir = envir) at debugme.R#1
2. env$fun() 
1. debugSource("C:/qc/zoe_home/S001_BaseKit/debugme.R")

The problem is that as.data.frame.lints should accept a linter value of NULL but doesn't.

A small example reproduces the crash:

lints <- structure(list(Lint(
   filename = "xyz",
   line_number = 1,
   column_number = 10,
   type = "style",
   message = "Use <-, not =, for assignment.",
   line = "asdfasdfasdfasdf"
   )), class = "lints")
lintr:::as.data.frame.lints(lints)

If you add a "linter = 'my_linter'", then there is no crash anymore.

Cheers,
Florent

@fangly
Copy link
Contributor Author

fangly commented Oct 24, 2016

I guess since other text arguments to Lint() default to "" and not NULL, "linter" should also default to "".
Here is a patch that implements this fix (with some added tests, of course):
0001-Changed-Lint-s-linter-default-to-prevent-as.data.fra.patch.zip

@fangly fangly changed the title Bug in as.data.frame.lints() Bug in as.data.frame.lints() [patch] Oct 26, 2016
@fangly
Copy link
Contributor Author

fangly commented Apr 13, 2017

This was fixed in the Lint() function by giving "linter" the default value "" (commit ae2870d).

@fangly fangly closed this as completed Apr 13, 2017
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

1 participant