1

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:

enter image description here

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.

Jan
12k7 gold badges25 silver badges36 bronze badges
asked Jul 9, 2024 at 16:36
5
  • 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. Commented 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. Commented Jul 9, 2024 at 17:36
  • Maybe this might help: stackoverflow.com/questions/43712370/… Commented Jul 9, 2024 at 17:41
  • @SamR You are right, thanks a lot. I now understand what is meant here ... Commented Jul 9, 2024 at 17:43
  • @SamR it's about both the colour and the underlines! Commented Jul 9, 2024 at 18:06

1 Answer 1

0

Looks like an issue with lintr rather than Positron specifically. I can replicate it in VS Code as follows:

text incorrectly linted

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 runs base::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:

text 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

answered Jul 9, 2024 at 17:32
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for your response! However, I am not familiar with this solution and couldn't fix it with your explanation. Could you please provide a more detailed explanation of what I should do?
@JoãoAugustoFreire you should just be able to create a file called .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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.