Using Google Drive Desktop, Shiny, and the new R 4.3.0 placeholder feature together causes apps to crash; why is this?

Originally posted in Stack Overflow (link)

I know R projects are not meant to be created in network drives, and I definitely will learn how to use Git properly because of this problem described below. But avoiding the problem itself is easy; I would like to know its cause, and if possible, why exactly it is dangerous to use RStudio and Google Drive Desktop together.

Problem description

In R 4.3.0, an 'experimental feature' has been added for the native pipe (|>) placeholder (_):

As an experimental feature the placeholder _ can now also be used in the rhs of a forward pipe |> expression as the first argument in an extraction call, such as _$coef. More generally, it can be used as the head of a chain of extractions, such as _$coef[[2]]. (link)

This syntax works well except when used inside a shiny app. Below is an example code of no practical use:


ui <- fluidPage(
  selectizeInput('col', 'Select column to view', choices = names(mtcars)),

server <- function (input, output, session) {
  output$table <- renderTable(mtcars |> _[[input$col]][1:10])

shinyApp(ui = ui, server = server)

Launch the app by clicking 'Run App' in RStudio then change the focus back to RStudio, and the app will immediately close (*). Try the same thing in an R project located in a network drive (e. g., Google drive desktop in my case) and additional anomalies can be observed: clicking on 'Run App' variably results in either the app launching successfully, nothing happening, or an unresponsive gray window appearing.

What I tried

The phenomenon does not occur when the new syntax is replaced with the old mtcars[[input$col]], or the Shiny app is launched from the R terminal, not RStudio. Also, as mentioned above, when the app is located in a local folder, only phenomenon (*) occurs and the more peculiar anomalies cannot be seen.

What I want to know

Avoiding the problem is easy; I just have to either quit using RStudio to access remotely located projects, or simply paraphrase the relevant sections of code. I have heard it is bad practice to use RStudio together with Google Drive Desktop, but I would like to know what exactly is going on here.

Also, phenomenon (*) can be reproduced even in local projects. Although it is innocuous, it is certainly unusual. So I suspect that working with a remote RStudio project is not entirely responsible for the problem, and there is some genuine mismatch between Shiny and the new placeholder syntax.

What I observed

The problem is not dependent on the relevant code being executed. Placing the following code inside renderTable() of the above example produces the same phenomena.

if (TRUE) {
} else {
  mtcars |> _[[input$col]][1:10]

The phenomenon is extremely variable. I tried set.seed() but the outcome of pressing 'Run App' does not seem to depend on the seed. I managed to coax out the following error message after many iterations, but cannot comprehend the meaning.

Error in base::suppressWarnings(base::try("_"[[input$col]], silent = TRUE)) : 
  invalid use of pipe placeholder (<input>:1:0)
Warning: stack imbalance in '<-', 37 then 32
Warning: stack imbalance in '{', 33 then 28

Listening on

Session info

> sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

[1] LC_COLLATE=Korean_Korea.utf8  LC_CTYPE=Korean_Korea.utf8    LC_MONETARY=Korean_Korea.utf8
[4] LC_NUMERIC=C                  LC_TIME=Korean_Korea.utf8    

time zone: Asia/Seoul
tzcode source: internal

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

other attached packages:
[1] shiny_1.7.4

loaded via a namespace (and not attached):
 [1] digest_0.6.31    later_1.3.1      R6_2.5.1         httpuv_1.6.11    fastmap_1.1.1    magrittr_2.0.3  
 [7] cachem_1.0.8     memoise_2.0.1    htmltools_0.5.5  lifecycle_1.0.3  promises_1.2.0.1 cli_3.6.1       
[13] xtable_1.8-4     sass_0.4.6       jquerylib_0.1.4  withr_2.5.0      compiler_4.3.0   rstudioapi_0.14 
[19] tools_4.3.0      bslib_0.4.2      ellipsis_0.3.2   mime_0.12        Rcpp_1.0.10      jsonlite_1.8.4  
[25] rlang_1.1.1

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.