Skip to content

Styler crashes when there comments in multi-curly-braced expressions #1264

@obsaditelnost

Description

@obsaditelnost

Hi,

the combination of multiple curly braces and comments seem to kill the styler. The following 2 reprex showcase the issue.

super short example

I know, it's a weird example, but it parses

library(styler)

example_code <- "
foo <- {{
  0# bar
}}

foo
"
styler::style_text(text = example_code, style = tidyverse_style)
#> Error in `handlers[[1L]]()`:
#> ! Styling resulted in code that isn't parsable. This should not happen.
#> ℹ This is an internal error that was detected in the styler package.
#>   Please report it at <https://github.com/r-lib/styler/issues> with a reprex (<https://tidyverse.org/help/>) and the full backtrace.

Created on 2025-07-18 with reprex v2.1.1

Session info
sessionInfo()
#> R version 4.4.3 (2025-02-28 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 22631)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8   
#> [3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                   
#> [5] LC_TIME=German_Germany.utf8    
#> 
#> time zone: Europe/Berlin
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] styler_1.10.3
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.37     fastmap_1.2.0     xfun_0.52         magrittr_2.0.3   
#>  [5] glue_1.8.0        R.utils_2.13.0    knitr_1.50        htmltools_0.5.8.1
#>  [9] rmarkdown_2.29    lifecycle_1.0.4   cli_3.6.4         R.methodsS3_1.8.2
#> [13] vctrs_0.6.5       reprex_2.1.1      withr_3.0.2       compiler_4.4.3   
#> [17] R.oo_1.27.1       R.cache_0.17.0    purrr_1.1.0       rstudioapi_0.17.1
#> [21] tools_4.4.3       pillar_1.11.0     evaluate_1.0.4    yaml_2.3.10      
#> [25] rlang_1.1.6       fs_1.6.6

more practical example

library(styler)
require(dplyr, warn.conflicts = FALSE, quietly = TRUE)

example_code <- "
require(dplyr, warn.conflicts = FALSE, quietly = TRUE)

df <- data.frame(foo = 1:5,bar = 6:10)

summarize_column <- function(data, column) {
  data %>% summarize(mean_value = mean({{ 
      column # Input via param
   }}), colname = as_label(enquo(column))) 
}

summarize_column(df, bar)
"
styler::style_text(text = example_code, style = tidyverse_style)
#> Error in `handlers[[1L]]()`:
#> ! Styling resulted in code that isn't parsable. This should not happen.
#> ℹ This is an internal error that was detected in the styler package.
#>   Please report it at <https://github.com/r-lib/styler/issues> with a reprex (<https://tidyverse.org/help/>) and the full backtrace.

Created on 2025-07-18 with reprex v2.1.1

Session info
sessionInfo()
#> R version 4.4.3 (2025-02-28 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 22631)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8   
#> [3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                   
#> [5] LC_TIME=German_Germany.utf8    
#> 
#> time zone: Europe/Berlin
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dplyr_1.1.4   styler_1.10.3
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.5       cli_3.6.4         knitr_1.50        rlang_1.1.6      
#>  [5] xfun_0.52         purrr_1.1.0       generics_0.1.4    glue_1.8.0       
#>  [9] htmltools_0.5.8.1 rmarkdown_2.29    R.cache_0.17.0    evaluate_1.0.4   
#> [13] tibble_3.2.1      fastmap_1.2.0     yaml_2.3.10       lifecycle_1.0.4  
#> [17] compiler_4.4.3    fs_1.6.6          pkgconfig_2.0.3   rstudioapi_0.17.1
#> [21] R.oo_1.27.1       R.utils_2.13.0    digest_0.6.37     R6_2.6.1         
#> [25] tidyselect_1.2.1  reprex_2.1.1      pillar_1.11.0     magrittr_2.0.3   
#> [29] R.methodsS3_1.8.2 tools_4.4.3       withr_3.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions