Skip to content

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

Closed
@fangly

Description

@fangly

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions