For loop with NULL fails
Closed this issue · 4 comments
It seems like when assigning a value with NULL
within a for
loop and executing it from a script file (i.e., command + enter
), it skips the code below and breaks the loop. For example:
for (i in 1:nrow(iris)) {
x <- NULL
print(i)
}
results on the radian terminal:
r$> for (i in 1:nrow(iris)) {
x <- NULL
}
r$> x <- substr(iris$Species[i], start = 1, stop = 2)
r$> }
Error: unexpected '}' in "}"
r$>
Code will work if running directly on the terminal.
I am running the code with VScode inside a container:
r$> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: aarch64-unknown-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS
Matrix products: default
BLAS: /usr/lib/aarch64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/aarch64-linux-gnu/lapack/liblapack.so.3.10.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C
[12] LC_IDENTIFICATION=C
time zone: UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] languageserver_0.3.12 httpgd_1.3.1 dplyr_1.1.3
loaded via a namespace (and not attached):
[1] gtable_0.3.4 jsonlite_1.8.7 compiler_4.3.1 tidyselect_1.2.0 Rcpp_1.0.11 xml2_1.3.5 EIAapi_0.1.2 later_1.3.1 tidyr_1.3.0 systemfonts_1.0.5 scales_1.2.1 yaml_2.3.7
[13] fastmap_1.1.1 ggplot2_3.4.3 R6_2.5.1 generics_0.1.3 htmlwidgets_1.6.2 tibble_3.2.1 munsell_0.5.0 pillar_1.9.0 rlang_1.1.1 utf8_1.2.4 lazyeval_0.2.2 viridisLite_0.4.2
[25] plotly_4.10.2 cli_3.6.1 magrittr_2.0.3 crosstalk_1.2.0 digest_0.6.33 grid_4.3.1 lifecycle_1.0.3 vctrs_0.6.4 glue_1.6.2 data.table_1.14.8 fansi_1.0.5 colorspace_2.1-0
[37] purrr_1.0.2 httr_1.4.7 ellipsis_0.3.2 tools_4.3.1 pkgconfig_2.0.3 htmltools_0.5.6.1
Did you turn on the bracketed paste mode in VSCode-R?
That worked!
I am running R inside a containerized environment and I have the r.bracketedPaste
argument set to true
on the .vscode\settings.json
file:
{
"r.alwaysUseActiveTerminal": true,
"r.bracketedPaste": true,
"r.sessionWatcher": true,
"r.plot.useHttpgd": true,
"grammarly.files.include": ["**/README.md", "**/readme.md", "**/*.txt"]
}
I always thought that at the project level, the settings.json
file is the source of truth.
Thanks for the prompt response!
Actually I have no idea what you have said 😜. Anyway, glad that you have figured it out.
When working in a containerized environment with the Dev Container
extension, it should enable you to define the VScode setting for the container regardless of your local VScode settings with the settings.json
file. The issue with the brackets should be taken care by the r.bracketedPaste": true
argument but it seems that it doesn't...