Skip to content

switching between source and visual modes introduces slashes in inline, evaluated R objects that break rendering #14508

Open

Description

@setgree

System details

RStudio Edition : Desktop
RStudio Version :  Version 2024.04.0-daily+534 (2024.04.0-daily+534)
OS Version      : macOS Sonoma 14.2.1

x86_64-apple-darwin20 (64-bit)

R Version       : 4.3.3 (2024-02-29)

Steps to reproduce the problem

Describe the problem in detail

Switching from source to visual -- even if I click the button by accident -- produces breaking changes in rendering because it's adding a bunch of backslashes (I guess it's trying to make sure things are formatted consistently?) but it's doing so in the middle fo R objects that Rstudio that is trying to evaluate.

Example:

Quitting from lines 296-297 (vegan-meta.Rmd)
Error:
! Failed to parse the inline R code: `r sum(self_report_outcomes\$outcome_category == "self_reported_more_less_outcome")\`
Reason: <text>:1:25: unexpected '\\'
1: sum(self_report_outcomes\
                            ^
Backtrace:
  1. FUN(X[[i]], ...)
  2. rmarkdown::render(input = file, envir = parent.frame())
  3. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  4. knitr:::process_file(text, output)
  9. knitr:::process_group.inline(group)
     ...
 14. base::tryCatch(...)
 15. base (local) tryCatchList(expr, classes, parentenv, handlers)
 16. base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 17. value[[3L]](cond)
 18. knitr:::stop2(...)

Related: #8073

Describe the behavior you expected

There should not be breaking changes depending on how you use the editor 😃

  • [ 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.
  • [ x] 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.

sessionInfo

b/c this paper takes a lot of libraries -- the core ones are tidyverse and metafor

> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

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

other attached packages:
 [1] googledrive_2.1.1   dplyr_1.1.4         stringr_1.5.1      
 [4] sessioninfo_1.2.2   purrr_1.0.2         knitr_1.45         
 [7] metafor_4.6-0       numDeriv_2016.8-1.1 metadat_1.2-0      
[10] Matrix_1.6-5       

loaded via a namespace (and not attached):
 [1] rappdirs_0.3.3    sass_0.4.8        utf8_1.2.4       
 [4] generics_0.1.3    stringi_1.8.3     lattice_0.22-5   
 [7] digest_0.6.34     magrittr_2.0.3    evaluate_0.23    
[10] grid_4.3.3        bookdown_0.38     papaja_0.1.2.9000
[13] fastmap_1.1.1     rprojroot_2.0.4   jsonlite_1.8.8   
[16] tinylabels_0.2.4  httr_1.4.7        fansi_1.0.6      
[19] scales_1.3.0      jquerylib_0.1.4   cli_3.6.2        
[22] rlang_1.1.3       munsell_0.5.0     withr_3.0.0      
[25] cachem_1.0.8      yaml_2.3.8        tools_4.3.3      
[28] gargle_1.5.2      colorspace_2.1-0  ggplot2_3.5.0    
[31] mathjaxr_1.6-0    here_1.0.1        curl_5.2.1       
[34] vctrs_0.6.5       R6_2.5.1          lifecycle_1.0.4  
[37] fs_1.6.3          pkgconfig_2.0.3   gtable_0.3.4     
[40] pillar_1.9.0      bslib_0.6.1       glue_1.7.0       
[43] xfun_0.42         tibble_3.2.1      tidyselect_1.2.0 
[46] rstudioapi_0.15.0 htmltools_0.5.7   nlme_3.1-164     
[49] rmarkdown_2.25    compiler_4.3.3    askpass_1.2.0    
[52] openssl_2.1.1    
### Tasks

Activity

  1. added
    new
    on Apr 2, 2024
  2. changed the title [-]switching between source and visual editors introduces a bunch of slashes that break rendering[/-] [+]switching between source and visual editors introduces slashes in inline, evaluated R objects that break rendering[/+] on Apr 2, 2024
  3. changed the title [-]switching between source and visual editors introduces slashes in inline, evaluated R objects that break rendering[/-] [+]switching between source and visual modes introduces slashes in inline, evaluated R objects that break rendering[/+] on Apr 2, 2024
  4. setgree commented on Apr 2, 2024

    @setgree
    Author
  5. ronblum commented on Apr 2, 2024

    @ronblum
    Contributor

    cc @ronblum

    🙂
    Thanks for bringing the issue over! I tried the code in both RStudio Desktop RStudio-2023.12.1-402 and 2024.04.0-daily+668 on Windows 11, but the back-and-forth switch works correctly. I only get the slashes after (incorrectly) removing the backticks.

    I'll try on MacOS next, but do you know if this worked for you in previous versions of RStudio?

  6. added
    visual markdown
    and removed
    new
    on Apr 2, 2024
  7. setgree commented on Apr 3, 2024

    @setgree
    Author

    IDK, I only recently started trying to compose reproducible documents in Rstudio.

    I just saved everything, committed, then switched to visual and back to source and saved again, and committed: setgree/vegan-meta@da6aaba

    Everything in this commit is unexpected behavior, IMO

  8. added this to the Product Backlog milestone on Apr 10, 2024
  9. setgree commented on Sep 18, 2024

    @setgree
    Author

    👋 just writing in to say I can reproduce this today on this document.

    I am in source mode, it works, I can knit.

    I switch to visual mode, and Rstudio inserts a random slash in an inline R object. Here is a commit showing with the change happening. (All I did was switch to visual mode).

    After that, I can't knit until I delete the slash again.

    I also notice that there are some typos in my original sentence:

    However, with just rpersuasion_psychology_model$N_studiesstudies fromr psych_studies_papers` to go on, we do not consider this an especially robust result, and we note that the pooled effect size is still substantively small.

    The ` characters are off. So maybe the visual mode editor is trying to fix this by putting in \ characters but then it ends up not knitting? In effect, it's alerting me to a mistake that I made, just in a very roundabout way 😃 😃

  10. setgree commented on Oct 24, 2024

    @setgree
    Author

    Here is a commit where I made no changes to the document besides switching from source to visual in Rstudio and clicking save

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugvisual markdown

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions