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

Code highlighting activated in .Rnw files after using \Sexpr with square brackets #14382

Closed
1 task
nickreich opened this issue Mar 6, 2024 · 5 comments
Closed
1 task
Assignees

Comments

@nickreich
Copy link

System details

RStudio Edition : Desktop
RStudio Version : Version 2023.12.1+402 (2023.12.1+402)
OS Version      : 12.7.3
R Version       : 4.3.2

Steps to reproduce the problem

I cannot attach a .Rnw file to the issue, but I have pasted in the complete text of the file saved as .Rnw that shows the problem.

\documentclass{article}

\begin{document}

<<>>=
my_data <- 1:5
@

The value of my data is \Sexpr{my_data}.

for example, you can see how the word "for" at the beginning of this sentence is not color-coded.

However, now we use \Sexpr{my_data[2]}.

for example, you can see how the word "for" at the beginning of this sentence is coded as if it were code (same with "if").

And if we put a quote mark here' now everything after it is seen as code quote'.

This appears to be a bug, and if there is an ending single quote the end of document is not read when knitted directly by the IDE. Although knitting the document via code like

knitr::knit('test.Rnw')

does work.

'

\end{document}

Describe the problem in detail

This problem with the RStudio IDE involves working with .Rnw or Sweave files and a specific use of \Sexpr{}, which is the tag for inline code. I have found that a use of \Sexpr{} that includes square brackets, such as \Sexpr{my_data[2]}, somehow activates the IDE to turn on code highlighting for all text after the square brackets. The file still does compile but the code highlighting is broken.

In the following screenshot you can see how on line 15 the word "for" is coded as text (while on line 11 it is not), and other parts of the document after apostrophes are also "commented out" in green text (including the \end{document} tag on line 25:
image

Describe the behavior you expected

The expected behavior is that code highlighting should never be turned on.

  • [ x ] I have read the guide for submitting good bug reports.
  • [ x ] I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • [ x ] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
@nickreich nickreich added bug new New incoming issues, ready for initial review. labels Mar 6, 2024
@kevinushey
Copy link
Contributor

Thank you for the bug report! I was able to reproduce; I'll take a look.

@kevinushey kevinushey added sweave and removed new New incoming issues, ready for initial review. labels Mar 6, 2024
@kevinushey kevinushey added this to the Chocolate Cosmos milestone Mar 6, 2024
@ronblum ronblum self-assigned this Mar 19, 2024
@ronblum
Copy link
Contributor

ronblum commented Mar 19, 2024

I'm unable to reproduce the the problem in earlier releases, so I can't verify this. @gtritchie Are you able to reproduce this, by chance?

@nickreich
Copy link
Author

I think this could be closed? per #14384

@gtritchie
Copy link
Member

gtritchie commented Mar 19, 2024

I think this could be closed? per #14384

Yes, we are working on validating the fix, and will close it once that's done.

@ronblum
Copy link
Contributor

ronblum commented Mar 19, 2024

Turned on rainbow parenthesis, and now I can reproduce the original problem and verify fixed in

  • RStudio Desktop 2024.04.0-daily+581 on MacOS 14.4
  • Posit Workbench 2024.04.0-daily+609.pro1 on Ubuntu 22.04 via Chrome on MacOS 14.4

@ronblum ronblum closed this as completed Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants