I've just started using Positron (Posit's new solution to integrate R and Python in an IDE that looks like RStudio but has many functionalities of VSCode) as it sounds like a great idea: https://github.com/posit-dev/positron
However, I primarily use data.table for data manipulation (instead of dplyr and its data frames), and Positron's text editor is highlighting variable names as written in data.table syntax (image below).
Positron highlighting variable names in data.table syntax:
In fact, see how it even highlights the dot here on .():
df[, .N, keyby = .(DC_ETAPA_AVALIADA, CD_ETAPA_AVALIADA)]
Does anyone have any ideas on how to fix it? I've tried opening an issue post on Positron's github page but I wasn't allowed to.
-
This is already known in a more general sense, see e.g. posit-dev/positron#1512, #2230 or #3688. We might expect this to be fixed in a future release.Jan– Jan2024年07月09日 17:33:37 +00:00Commented Jul 9, 2024 at 17:33
-
@Jan one of us has misunderstood the question! I thought it was about underlining variable names rather than the colours.SamR– SamR2024年07月09日 17:36:55 +00:00Commented Jul 9, 2024 at 17:36
-
Maybe this might help: stackoverflow.com/questions/43712370/…Ifeanyi Idiaye– Ifeanyi Idiaye2024年07月09日 17:41:13 +00:00Commented Jul 9, 2024 at 17:41
-
@SamR You are right, thanks a lot. I now understand what is meant here ...Jan– Jan2024年07月09日 17:43:27 +00:00Commented Jul 9, 2024 at 17:43
-
@SamR it's about both the colour and the underlines!João Augusto Freire– João Augusto Freire2024年07月09日 18:06:49 +00:00Commented Jul 9, 2024 at 18:06
1 Answer 1
Looks like an issue with lintr rather than Positron specifically. I can replicate it in VS Code as follows:
The code is fine but the object usage linter disagrees. The docs note this linter exists to:
Check that closures have the proper usage using
codetools::checkUsage(). Note that this runsbase::eval()on the code, so do not use with untrusted code.
I generally disable this anyway, because it's too conservative and because I do not expect copying code into a text file should cause it to be evaluated.
The fix is to create a .lintr file disabling the object usage linter:
linters: linters_with_defaults(
object_usage_linter=NULL)
encoding: "UTF-8"
This should now be correctly linted:
The .lintr file can be either in the project root directory, or in your home directory to apply globally. See the docs for details
2 Comments
.lintr in the same directory as the script in question and copy the text in my answer into it. You may need to restart Positron - I don't know as I haven't used it. See here for all possible .lintr file locations: lintr.r-lib.org/articles/lintr.html#other-configuration-options