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

LSP diagnostics shows lintr error although lintr::lint_package() does not #652

Open
jsr-p opened this issue Jan 24, 2024 · 4 comments
Open

Comments

@jsr-p
Copy link

jsr-p commented Jan 24, 2024

Hi

I am developing a package where I use .data from rlang together with dplyr.
The code snippet is

#' @export
#' @importFrom rlang .data
my_fun <- function(df) {
  df |> dplyr::mutate(
    x = .data[[col]]
  )
}

with NAMESPACE file:

# Generated by roxygen2: do not edit by hand

export(my_fun)
importFrom(rlang,.data)

When running lintr::lint_package() inside RStudio I do not get any errors.
image
However, using the rlanguageserver inside Neovim gives the following error:

image

My sessionInfo() is:

> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.12.0 
LAPACK: /usr/lib/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Copenhagen
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lintr_3.1.1           languageserver_0.3.16 testpkg_0.0.0.9000   
[4] devtools_2.4.5        usethis_2.2.2        

loaded via a namespace (and not attached):
 [1] generics_0.1.3     utf8_1.2.4         xml2_1.3.5         stringi_1.8.3     
 [5] digest_0.6.33      magrittr_2.0.3     pkgload_1.3.3      fastmap_1.1.1     
 [9] rprojroot_2.0.4    processx_3.8.3     pkgbuild_1.4.3     sessioninfo_1.2.2 
[13] brio_1.1.4         backports_1.4.1    ps_1.7.5           urlchecker_1.0.1  
[17] promises_1.2.1     purrr_1.0.2        fansi_1.0.6        codetools_0.2-19  
[21] lazyeval_0.2.2     cli_3.6.2          shiny_1.8.0        crayon_1.5.2      
[25] rlang_1.1.2        ellipsis_0.3.2     remotes_2.4.2.1    withr_2.5.2       
[29] cachem_1.0.8       parallel_4.3.2     tools_4.3.2        memoise_2.0.1     
[33] dplyr_1.1.3        httpuv_1.6.13      vctrs_0.6.5        cyclocomp_1.1.1   
[37] R6_2.5.1           mime_0.12          lifecycle_1.0.4    stringr_1.5.1     
[41] fs_1.6.3           htmlwidgets_1.6.3  miniUI_0.1.1.1     callr_3.7.3       
[45] pkgconfig_2.0.3    desc_1.4.3         rex_1.2.1          pillar_1.9.0      
[49] later_1.3.2        data.table_1.14.8  glue_1.6.2         profvis_0.3.8     
[53] Rcpp_1.0.11        tidyselect_1.2.0   xfun_0.41          tibble_3.2.1      
[57] rstudioapi_0.15.0  knitr_1.45         xtable_1.8-4       htmltools_0.5.7   
[61] testthat_3.2.1     compiler_4.3.2     roxygen2_7.2.3     xmlparsedata_1.0.5

and I am using the newest r-languageserver:
image

The only way that I can make it go away is by writing in my .lintr file:

linters: linters_with_defaults(
    object_usage_linter = NULL
  )

but how can I do it correctly :D?

Thank you!

@pit00
Copy link

pit00 commented Feb 6, 2024

I have a similar problem at VS Code.
(also did the same steps)

@pit00
Copy link

pit00 commented Feb 7, 2024

I put a .Rprofile file at project folder, with devtools::load_all().
This workaround solves my linter problems, can you do the same?

@jsr-p
Copy link
Author

jsr-p commented Feb 8, 2024

@pit00 does not work for me; still getting the diagnostic message :/

@luciorq
Copy link

luciorq commented Feb 8, 2024

This is not really a solution for your problem, but just namespace the .data object.

With:

my_fun <- function(df, col) {
  
  .data <- rlang::.data
  
  df |> dplyr::mutate(
    x = .data[[col]]
  )
}

This could potentially also bring some safety regarding namespace collisions.

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