Skip to content

RStudio 2024.04.0,735 Chunk Parsing Issue... #14684

Closed

Description

@olearydj

Original post: https://forum.posit.co/t/rstudio-wont-run-chunks/186563
Added here after confirming that reverting to 2023.12.1,402 corrects the issue, without any other changes.

RS 2024.04 refuses to run a qmd file in the IDE that runs / builds fine using Quarto to render to PDF / HTML or in properly configured VS Code.

System details

RStudio Edition : Desktop
RStudio Version :  2024.04.0,735
OS Version      :  x86_64-apple-darwin20 Running under: macOS Sonoma 14.3.1
R Version       :  4.4.0
Quarto version :  1.4.554

Steps to reproduce the problem

  1. Start RStudio 2024.04
  2. Create a new QMD file
  3. Paste the contents of the code below into the file.
  4. Select Run All Chunks
  5. Nothing happens.

There is no need to install the required packages or have access to the data. Run All Chunks should at least attempt to load the libraries in the first chunk, but it does not. There is no response at all - no error, no warning, nothing except a new entry in my rsession log file:

2024-05-09T00:11:46.233228Z [rsession-djo] ERROR CLIENT EXCEPTION (rsession-djo): (TypeError) : Cannot read properties of null (reading 'row');|||org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTargetScopeHelper.java#110::getSweaveChunkInnerRange|||org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java#6495::execute|||org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java#6484::executeSweaveChunk|||org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java#6124::executeChunk|||org/rstudio/studio/client/workbench/views/source/editors/text/rmd/ChunkContextCodeUi.java#81::runChunk|||org/rstudio/studio/client/workbench/views/source/editors/text/rmd/ChunkContextToolbar.java#172::onBrowserEvent|||com/google/gwt/user/client/DOM.java#1432::dispatchEvent|||com/google/gwt/user/client/impl/DOMImplStandard.java#317::dispatchEvent|||com/google/gwt/core/client/impl/Impl.java#296::apply|||com/google/gwt/core/client/impl/Impl.java#335::entry0|||rstudio-0.js#-1::eval|||Client-ID: 33e600bb-c1b1-46bf-b562-ab5cba070b0e|||User-Agent: Mozilla/5.0 (Macintosh Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2024.04.0+735 Chrome/120.0.6099.291 Electron/28.2.6 Safari/537.36

When the libraries and data are available, the chunk that refuses to run is fig-s1-progress. Those before it will run individually.

Describe the problem in detail

Here is the offending code. I'm sorry I wasn't able to shrink it more, but it will give you a reproducible case.

# Results {#25-results}

```{r load-libs}
#| message: false

library(tidyverse)
library(readxl)
```

```{r load-data}

car_results <- read_xlsx(
  "./data/combined_results.xlsx",
  na = c("", "N/A"),
  sheet = "car results"
)

demographics <- read_xlsx(
  "./data/combined_results.xlsx",
  na = c("", "N/A"),
  sheet = "demographics"
)
```

```{r def-cust-theme}
base_color <- "#69b3a2"

# Define a custom theme for ggplot
custom_theme <- function() {
  theme_minimal(base_size = 10) +
    theme(
      plot.title.position = "plot",
      plot.title = element_text(face = "bold"),
      # plot.subtitle = element_text(face = "italic"),
      # plot.caption = element_text(color = "grey50"),
      # axis.title.x = element_text(face = "bold"),
      # axis.title.y = element_text(face = "bold"),
      # axis.text = element_text(color = "black"),
      # axis.line = element_line(color = "grey80"),
      # legend.position = "bottom",
      # legend.background = element_rect(fill = "white", colour = "grey50"),
      # legend.key = element_rect(fill = "white", colour = "grey50"),
    )
}

# Set the custom theme as the default theme
theme_set(custom_theme())
```

```{r study-metadata}

participant_count <- demographics |>
  pull(participant) |>
  n_distinct()

# Convert the trial_datetime to Date type
demographics <- demographics |>
  mutate(
    trial_date = as.Date(
      as.POSIXct(trial_datetime, format = "%Y-%m-%d %H:%M:%S")
    )
  )

# Get the first and last date
first_trial_date <- demographics |>
  summarize(first_date = min(trial_date)) |>
  pull(first_date)

last_trial_date <- demographics |>
  summarize(last_date = max(trial_date)) |>
  pull(last_date)

trial_start_str <- str_glue(
  "{month(first_trial_date)}/{day(first_trial_date)}"
)
trial_end_str <- str_glue(
  "{month(last_trial_date)}/{day(last_trial_date)}"
)
trial_year_str <- str_glue("{year(last_trial_date)}")

# start, end = Feb 10, Apr 27 2023
```


```{r fig-s1-progress}
#| fig-cap: "Daily Trial Administration and Completion Percentage"
#| fig-height: 4

# Count experiments per day
daily_counts <- demographics |>
  group_by(trial_date) |>
  summarize(daily_count = n()) |>
  arrange(trial_date)

# Calculate the cumulative count of experiments
daily_counts <- daily_counts |>
  mutate(cumulative_count = cumsum(daily_count))

# Calculate remaining experiments
daily_counts <- daily_counts |>
  mutate(
    percentage_complete = (cumulative_count / participant_count) * 100
  )

pc_eng <- as.character(english::english(participant_count))
pc_eng <- str_replace(pc_eng, "^.", str_to_upper)
subtitle <- str_glue("{pc_eng} Learning and Recall Experiments Conducted between {trial_start_str} and {trial_end_str} of {trial_year_str}")

# Plotting
ggplot(daily_counts, aes(x = trial_date)) +
  geom_line(
    aes(y = daily_count, group = 1),
    color = base_color,
    linewidth = 1,
    alpha = 0.5
  ) +
  geom_line(
    aes(y = percentage_complete, group = 1),
    color = base_color,
    linewidth = 1.25,
    alpha = 1
  ) +
  scale_y_continuous(
    name = "Trials Administered",
    sec.axis = sec_axis(~., name = "Percentage Complete"),
    position = "right",
    limits = c(0, 100)
  ) +
  labs(
    title = "First Session Progress",
    subtitle = subtitle,
    x = element_blank(),
    y = element_blank()
  ) +
  custom_theme()
```


::: content-hidden
TODO: complete above paragraph about second session.
:::

::: content-hidden
MAYBE: perform analysis to evaluate differences between pilot and main group

Pilot Study Comparison
- Compare the key measures (e.g., performance, workload, usability) between the pilot study (n=8) and main study (n=54) participants
- Use descriptive statistics and visualizations to present these comparisons
- Discuss any notable similarities or differences between the two groups

Statistical Power and Sample Size Considerations
- Present the results of statistical power analyses based on the observed effect sizes and the planned statistical tests
- Discuss the adequacy of the sample size for detecting meaningful effects
- Consider the potential impact of including or excluding the pilot study data on the statistical power and precision of the estimates
- sample size calculation / justification: power analysis, practical considerations, precedent

Decision on Pilot Study Inclusion
- Based on the findings from 5.2.3 and 5.2.4, make a decision on whether to include the pilot study data in the main analysis
- Clearly report your decision and rationale, considering factors such as data comparability, study design modifications, and statistical power
:::

```{r drop-pilot-data}
# drop participants in pilot study (first eight)
demographics <- demographics |>
  filter(!(participant >= 1001 & participant <= 1010))

# drop event data from the pilot study
car_results <- car_results |>
  filter(!(participant >= 1001 & participant <= 1010))
```

```{r def-to-factors}

# safely convert data to ord / cat factors
# create levels / labels as required and identify / warn about mismatches

to_factors <- function(
    column,
    levels = NULL,
    labels = NULL,
    ordered = FALSE) {
  if (is.null(levels)) {
    levels <- unique(na.omit(column))
  }

  if (is.null(labels)) {
    labels <- levels
  }

  mismatched <- setdiff(unique(na.omit(column)), levels)

  if (length(mismatched) > 0) {
    # Append mismatched values to levels and labels with a specific prefix
    bad_levels <- paste("Bad -", mismatched)
    levels <- c(levels, mismatched)
    labels <- c(labels, bad_levels)
    warning(
      "Mismatched or unexpected values incorporated: ",
      paste(bad_levels, collapse = ", ")
    )
  }

  # Proceed to convert to factor using cleaned-up data
  factor_column <- factor(column,
    levels = levels, labels = labels,
    ordered = ordered
  )

  return(factor_column)
}
```

Describe the behavior you expected

I expect that Run All Chunks will at least attempt to run the first chunk or throw an error about bad QMD formatting. It does nothing.

  • 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

  1. added
    new
    on May 9, 2024
  2. ronblum commented on May 10, 2024

    @ronblum
    Contributor

    @olearydj Thank you for raising this! This looks like the same as issue #14652 (the one that you referenced), so I'm closing this issue, but I'll make a note in #14652 to validate fixes with your code, as well.

  3. ronblum commented on May 30, 2024

    @ronblum
    Contributor

    Verified in RStudio Desktop 2024.04.2+762.pro1 that "run all chunks" works. I don't have a necessary data file, but the chunks are executed.

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

    bugnew

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions