r-lib / lintr

Static Code Analysis for R
https://lintr.r-lib.org
Other
1.2k stars 187 forks source link

bookdown repositories are incorrectly scoped for linting #184

Closed maxheld83 closed 7 years ago

maxheld83 commented 7 years ago

When using bookdown in RStudio (though I suspect this problem will exist elsewhere, too), it's customary not necessarily to call library(foo) in the same *.Rmd as some function foo::bar() therein. Erroneously, RStudio (aka. lintr) will then lint foo::bar() as:

no symbol named 'bar()' in scope

Though when run through bookdown (which the repository and RStudio "know") with the default "Merge-Then-Knit" strategy, there is, in fact no problem.

This is a bit annoying when editing a bookdown, and I'm wondering whether this could be fixed in lintr by somehow scoping all *.Rmds inside a project.

@verenakasztantowicz had the same issue.

Hoping this is the right place, and it's not an RStudio or bookdown issue.


MWE (sort of, not a fully-fledge bookdown, but I hope you get the idea)

Let's have an index.Rmd like so:

--- 
title: "A not so minimal not so working example"
author: "Calvin, Hobbes the Tiger"
site: bookdown::bookdown_site
---

```{r preamble, echo=FALSE, include=FALSE}
library(ggplot2)
```

```{r test-in-index}
ggplot("foo")
```

This lints just fine:

finelint

Try the same thing in first-chapter.Rmd, in the same repository and at root and no such luck:

```{r test-in-index}
ggplot("foo")
```

badlint

jimhester commented 7 years ago

The RStudio IDE does not use lintr for its code linting. You need to open an issue at https://support.rstudio.com/hc/en-us

maxheld83 commented 7 years ago

yikes, so sorry about that. Thanks for the pointer. Why did I think that?