Skip to content

Behavior of lintr before/after calling library #382

@tvatter

Description

@tvatter

Hi,

I use neovim with ale + Nvim-R and it got me wondering about how lintr works.

Let's say that I have the following file called test.R:

library(purrr)

n <- 10
map(1:n, function(x) rnorm(x))
myfun <- function(n) {
  map(1:n, function(x) rnorm(x))
}

If I start a new R session and call lintr::lint("test.R"), I get a marker related to the second map ("no visible global function definition"), whereas if I call library(purrr) first, I do not get a marker.

  1. Why do I never get a marker for the first map?
  2. In the second case (i.e., if I call lintr::lint after library), how does lintr "knows" that map is "available"?

While I ask the first question by curiosity, I ask the second question because, as mentioned, I use ale and Nvim-R. In this context, although I often load packages in the R session opened with Nvim-R, the markers for missing global function definitions never disappear after loading the appropriate packages.

This is obviously expected since, to the best of my knowledge, there is no connection between ale and Nvim-R. But I am trying to understand where lintr looks for the information about the loaded namespaces with the final goal to get ale to use the current Nvim-R session to make the markers related to global function definitions from packages that are loaded disappear.

I am not sure whether I explained clearly the issue, my apologies if not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions