Repository navigation
Description
System details
RStudio Edition : Desktop
RStudio Version : 2021.09.0 Build 351 - Ghost Orchid" Release (077589bc, 2021-09-20) for Windows
OS Version : Windows 10 x64 (build 22000)
R Version : R version 4.1.2 (2021-11-01)
Steps to reproduce the problem
- Create and save the following
.Rmddocument within the desired directory in your system:
---
title: "Reproduce issue with backslashes in citations"
author: "Pedro Henrique P. Braga"
date: "11/11/2021"
bibliography: references.bib
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
- Create a
references.bibfile containing the code chunk below and save it to the same directory as the.Rmdfile:
@Manual{R-rmarkdown,
title = {rmarkdown: Dynamic Documents for R},
author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone},
year = {2020},
note = {R package version 2.6},
url = {https://github.com/rstudio/rmarkdown},
}
-
Open the
.Rmdfile in RStudio and switch from the script-based view to the "Visual Editor" (shortcut Ctrl or Command+Shift+F4); -
Add a citation by typing
[@R-rmarkdown]after the first paragraph in the prose written below the YAML;
-
Knit the document.
-
Disable the "Visual Editor" (shortcut
CtrlorCommand+Shift+F4).
Describe the problem in detail
Backslashes are added to citations created in the "Visual Editor" mode. They are apparent when switching back from the Visual Editor mode, and this results in the incorrect rendering of citations and references. See the output of the document below:
Describe the behaviour you expected
The expectation is that citations added when using the "Visual Editor" mode are reflected correctly in the code-based view of the .Rmd script and that citations and references are rendered correctly within the PDF or HTML document.
- I have read the guide for submitting good bug reports.
- 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.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.



Activity
pedrohbraga commentedon Nov 11, 2021
I am also adding another example, non-reproducible, which also demonstrates this same issue I am having, at a larger scale.
Note how citations are not correctly rendered and how backslashes are added to the citations within the
.Rmddocument.[-]Backslashes are added to citations when using the RMarkdown Visual Editor and result in the incorrect rendering of documents [/-][+]Backslashes are added to citations when using the RMarkdown Visual Editor, resulting in the incorrect rendering of documents [/+]Dijkie85 commentedon Nov 12, 2021
Not sure if it's related to this, but I found that working with multiple child Rmd's will result in duplicate references between documents, because the visual editor numbers each reference in each document without regard for previous children.
So, even if the first reference in 2.Rmd is "[^2-1]" it will be converted to "[^1"] and overlap with references from 1.Rmd.
ronblum commentedon Nov 12, 2021
@pedrohbraga Thank you for raising this! We've certain cases in which the backslashes are added incorrectly. However, I can't reproduce this problem: It works for me in both
Did this problem occur for you in previous versions of RStudio, such as 1.4.1717 or earlier?
@Dijkie85 The issue with citations in children files appears to be a different problem. Can you file a new issue for this? It would also be helpful to include sample files, both the parent and child files. Thanks!
balthasars commentedon Nov 12, 2021
I have the same issue in RStudio version 2021.9.1.372 on macOS 11.6. @ronblum is there a way of switching into the visual mode reproducible?
In my case, somewhat strangely, not all citations in the document end up being formatted like this, however. Some retain the correct formatting
Dijkie85 commentedon Nov 12, 2021
@ronblum Will do. Thanks!
edit: opened #10078
ronblum commentedon Nov 12, 2021
@balthasars Would you be willing to provide an example of a file in which some citations keep the correct formatting and others don't? I can try it and see if I see the same issue.
pedrohbraga commentedon Nov 15, 2021
@ronblum and others,
Here follows another example that should be reproducible in your environment and that (hopefully) brings to the same outcome I am having here.
.Rmdfile:main_references.bibfile, within the same directory as the.Rmdfile :Switch to Visual Editor mode;
Add the citation
@castro-insua2018srto the sentence "How climatic niches contribute to the formation and maintenance of biodiversity patterns?"`, as follows:Note: Instead of copying and pasting, type
; @castro-insua2018srwithin the citation tag that already exists there.Expected behaviour
Following Step 5, you should see that backslashes have been added before the square brackets in all citations.
Please let me know if you need a video to be recorded or further information about my system and about my RStudio and R sessions.
bryanpmayfield commentedon Nov 16, 2021
I am having the same exact issue using RStudio version 2021.09.0 on MaCOS 12.0.1.
Also, not sure if this has anything to do with the canonical visual mode setting, but just in case I have tried it both with and without that setting set to true (in both global options and project options) and the problem persists.
@pedrohbraga Have you found a work around for this?
ronblum commentedon Nov 16, 2021
@pedrohbraga Thank you! I can reproduce this issue based on your code and precise steps—I appreciate it. Specifically, tested using RStudio Desktop 2021.09.0+351 on MacOS 12. I was also able to reproduce is it by switching back and forth between source and visual mode—sometimes once was enough, sometimes twice.
49 remaining items
ronblum commentedon May 23, 2022
Reopening because it looks like there's another version of this issue, which came up in #11198 and I can reproduce in PT and SW. Let me know if I should open a separate issue instead.
[Copied from @Robinlovelace's note in #11198.]
travis-main.zip
No problem. See attached another maybe reproducible example. Every time I open this up in visual mode all the citations get changed from something like this:
to this:
which is frustrating to say the least...
ronblum commentedon May 24, 2022
Closed in favor of opening #11279.