Repository navigation
Description
System details
RStudio Edition : Desktop
RStudio Version : 2022.12.0+353
OS Version : macOS 11.7
R Version : R version 4.2.1 (2022-06-23)
Steps to reproduce the problem
Clone https://github.com/hadley/r-pkgs.
Try to insert a cross-reference to a heading using its label. This often doesn't work.
Describe the problem in detail
I'm doing a lot of work in the R Packages book project, which is now a Quarto book and I'm mostly using the Visual Editor. I need to use Insert > Cross Reference a lot, but the cross references I can access in that pop-up are very incomplete and seem to change in ways I do not understand (i.e. over the course of one "work session" it feels like certain labels are there for a while then disappear??). This is very subjective, but it feels like I can summon the cross reference I'm targetting about (or less than) half the time.
I do periodically build the whole book to try to combat this but that doesn't seem to make a dramatic, persistent improvement. And, in this case of a book, that's quite time-consuming.
My workarounds are also pretty tough, because of interactions with other issues. I manually find the section I want to reference (but there are Find in Files problems #12484). I then click on the ... to bring up the "Edit Attributes" pop-up. Then I copy the ID, e.g. #sec-sw-dev-practices-git-github. Then I return to location where I want to insert the cross reference and paste. I then replace the leading # with @. And ?50%? of the time this actually gets replaced with a \@, although only the @ is visible in Visual mode (possibly connected to #11279). Maybe this is related to whether RStudio is currently aware of a specific cross-reference label? I usually have to switch to Source mode (now I have to find the cursor #8411), so that I can see and remove the backslash. Then I go back into visual mode (#8411 again).
Describe the behavior you expected
I expect all of the explicitly labelled sections to be available in the cross reference search pop up.
As a coping mechanism, I've written small scripts using the parsermd package, for example, to help surface labels I can use as cross references. This is pretty sub-optimal, though, for many reasons. I wish I could just access these labels via the pop-up.
library(tidyverse)
library(parsermd)
file <- "dependencies-in-practice.Rmd"
(rmd <- parse_rmd(file) |>
rmd_select(has_type("rmd_heading")))
#> └── Heading [h1] - Dependencies: In Practice {#sec-dependencies-in-practice}
#> ├── Heading [h2] - Introduction
#> ├── Heading [h2] - Confusion about `Imports`
#> ├── Heading [h2] - Conventions for this chapter
#> ├── Heading [h2] - `NAMESPACE` Workflow {#sec-dependencies-NAMESPACE-workflow}
#> ├── Heading [h2] - RStudio
#> ├── Heading [h2] - Package is listed in `Imports` {#sec-dependencies-in-imports}
#> │ ├── Heading [h3] - In code below R/
#> │ │ └── Heading [h4] - How to *not* use a package in Imports
#> │ ├── Heading [h3] - In test code {#sec-dependencies-in-imports-in-tests}
#> │ └── Heading [h3] - In examples and vignettes
#> ├── Heading [h2] - Package is listed in `Suggests` {#sec-dependencies-in-suggests}
#> │ ├── Heading [h3] - In code below `R/` {#sec-dependencies-in-suggests-r-code}
#> │ ├── Heading [h3] - In test code {#sec-dependencies-in-suggests-in-tests}
#> │ └── Heading [h3] - In examples and vignettes {#sec-dependencies-in-suggests-in-examples-and-vignettes}
#> ├── Heading [h2] - Package is listed in Depends {#sec-dependencies-in-depends}
#> │ ├── Heading [h3] - In code below `R/` and in test code
#> │ └── Heading [h3] - In examples and vignettes
#> ├── Heading [h2] - Package is a nonstandard dependency {#sec-dependencies-nonstandard}
#> │ └── Heading [h3] - Depending on the development version of a package
#> ├── Heading [h2] - CRAN
#> │ └── Heading [h3] - `Config/Needs/*` field {#sec-dependencies-nonstandard-config-needs}
#> ├── Heading [h2] - Exports
#> │ ├── Heading [h3] - What to export
#> │ └── Heading [h3] - Re-exporting
#> └── Heading [h2] - Imports and exports related to S3
# parsermd doesn't know about callouts, so they erroneously appear as sec_h2
dat <- as_tibble(rmd) |>
select(matches("sec_h[23]")) |>
filter(!str_detect(sec_h2, "Submitting to CRAN")) |>
separate_wider_regex(
everything(),
c("text" = "[^\\{]*", " [{]", label = ".*", "[}]"),
names_sep = "_", too_few = "align_start"
)
dat |>
select(ends_with("label"))
#> # A tibble: 25 × 2
#> sec_h2_label sec_h3_label
#> <chr> <chr>
#> 1 <NA> <NA>
#> 2 <NA> <NA>
#> 3 <NA> <NA>
#> 4 #sec-dependencies-NAMESPACE-workflow <NA>
#> 5 <NA> <NA>
#> 6 #sec-dependencies-in-imports <NA>
#> 7 #sec-dependencies-in-imports <NA>
#> 8 #sec-dependencies-in-imports <NA>
#> 9 #sec-dependencies-in-imports #sec-dependencies-in-imports-in-tests
#> 10 #sec-dependencies-in-imports <NA>
#> # … with 15 more rows- 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
DavisVaughan commentedon Jan 25, 2023
The autocompletion seems rather finicky too:
Screen.Recording.2023-01-25.at.1.39.41.PM.mov
jjallaire commentedon Feb 9, 2023
One of the problems here is that we don't get an updated index until you render the document. So if you add a crossref to one chapter you can't use it in another chapter until you render.
We will be overhauling this in our Quarto LSP (whereby we will proactively maintain an index of everything on disk). I'm tracking that change here: quarto-dev/quarto#78
jennybc commentedon Feb 9, 2023
This scenario comes up a lot in my current workflow. I.e. I'm working on chapter A and realize I should reference a section of chapter B. But that section doesn't have a (good) label yet, so I go add it to chapter B. Then I wish I could use it immediately back in chapter A. So if saving a source file tickled something to update the index, that would be great. And/or an explicit gesture to update the index of cross refs.
github-actions commentedon Aug 12, 2023
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.
olivroy commentedon Aug 14, 2023
This is still of interest I believe.
github-actions commentedon Mar 2, 2024
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.
jennybc commentedon Mar 2, 2024
Still interested.