You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Running chunk should submit code in single "block" #3520
It works this way because we need R to evaluate each line individually -- that way we can avoid sending further lines to R when an error occurs, and can also track the production of artifacts such as plots to their originating lines.
We might be able to paper over this in the history so that it still looks like all of the lines went to R in one go.
@jmcphers could a single expression at least be one blob in the history, as it is for non-Rmd code? E.g. an expression like
data.frame(
x=1,
y=2
)
appears in history line-by-line when run from an Rmd (whether the whole chunk or ctrl-enter), but is one history entry when run from an R script (ctrl-enter, shift-enter, etc) or the console as demonstrated above.
I think the expression-specific behavior is a regression, as at some point in the past the expressions were combined in history, though I couldn't tell you how long ago that was; at least 3 months, possibly much longer, and I tend to run latest-release versions.
Perhaps a separate issue, but for executing a selection from within a code chunk, I definitely think the approach for source files should be followed, i.e. a single blob as noted above. This use case is much more likely to involve subsequent history fiddling by the user than the full chunk, I suspect. And it's just plain inconsistent.
Even in the complete chunk case, executing top level expression by expression makes much more sense than line by line, if the parsing can be done to allow this. (No error or artifact linking downside, is there?)
Note that line by line history with incomplete statements is not only pretty useless for experimental modifications of the executed code from the console, it makes it painful to navigate to other parts of the history that may or may not have come from the notebook code.
I also feel like there's been a regression, though I can't validate that (and wasn't there multi-line functionality in the History pane at one point?).
For quite some time I thought something was fundamentally wrong with the debugging options of RStudio. From another R IDE, I was used that the following code would stop at Var1 <- MyFun(Var1) such that Var1 finally takes the value 12 and not 14 when the code is send using ctrl+enter.
I am clearly in favour of sending the text selection in the editor as a block and not line by line. It would have great advantages for debugging, since commands after buggy code wouldn't spoil any objects.
To me, having different history behavior for "execute selection", depending on whether the selection is in a .Rmd file or a .R file, is a bug. Making them consistent is not an enhancement, it's how it should always have worked. If you feel this is different from the original issue posted, I'm happy to open a new one!
This issue makes writing analysis notebooks very cumbersome in practice. A fix would be greatly appreciated.
A workaround is to write the notebook as an R script and process them with rmarkdown::render (~ spin + knitr), but then one does not get all the other features of Rmd notebooks (chunk submission, embedded graphs, etc...).
I believe 2. and 3. should behave like they do for a .R file (from the console history point of view, at least). For 1. I would prefer the @ClaytonJY suggestion of grouping expression by expression (i.e. act as though 2. was used for all the chunk code at once), but the @hadley ask of the whole chunk as a single history item would be an improvement.
Related issue, perhaps requires a separate item, but it would be nice to think this would also fix it: it seems like we lost grouped line selection in the History pane at some point in the product history. A user almost never wants to select a single line from a multi-line expression in the History pane to copy to source or console, but to get the whole expression requires extending the selection with shift-click or some such operation. Annoying.
Reacted by Clayton Yochum, Zach Reitz, bigO6377 and T. Crow
Hey guys, is there any update/fix to these issues? Namely:
Scrolling upward in console will show a multiline block of code as individual lines when the code was executed from a .Rmd (though for code executed from a .R file, it does show the entire code block as desired)
History tab not grouping multiline commands into a single entity (regardless of whether executed from a .R, a .Rmd, or from the console directly
Using the following version/OS
> RStudio.Version()
$citation
To cite RStudio in publications use:
RStudio Team (2021). RStudio: Integrated Development Environment for R. RStudio, PBC, Boston, MA URL
http://www.rstudio.com/.
A BibTeX entry for LaTeX users is
@Manual{,
title = {RStudio: Integrated Development Environment for R},
author = {{RStudio Team}},
organization = {RStudio, PBC},
address = {Boston, MA},
year = {2021},
url = {http://www.rstudio.com/},
}
$mode
[1] "desktop"
$version
[1] ‘2021.9.0.351’
$long_version
[1] "2021.09.0+351"
$release_name
[1] "Ghost Orchid"
Reacted by bigO6377, Parker Barnes, Alexander Hoyle, kdkavanagh and olivroy
I would consider it a feature if any solution here would also prevent subsequent lines from being fed to an empty readline command that is waiting for user input. For example, we might expect the following behavior when sourcing this block:
x<-readline() # user enters something
rm(x)
x#> Error in eval(expr, envir, enclos): object 'x' not found
I agree with @pqmatagi and others re: the issue with the console history after running a selection from a code chunk in rmarkdown RMD or quarto QMD files. Is this "selection" problem considered the same as the "Full chunk" problem and thus being tracked in this Issue? I often use Ctrl-Enter to run a multi-line operation (joined by pipes) in a chunk, and this more or less ruins the console history because each individual line (i.e., that which is captured by the history) is useless on its own. Would be nice to see consistent behavior with .R files for this, since it's highly useful for tinkering in interactive mode.
Verified in RStudio Desktop 2024.11.0-daily+331 on Windows 11.
Used variations of the examples above, and guidance from the QA notes:
Execution of a single chunk's contents (via the Run button),
Execution of a subset of code in a chunk (via Cmd + Enter),
Execution of all chunks in a document (via Run All or similar)
Checked both Console Pane, which groups the chunks, and the History Pane, which treats lines separately. Checked both Rmd and Qmd. With "run all", the chunks are correctly treated as separate blocks, not all as one.
Question: I found interesting behavior with R scripts. When using Ctrl-Shift-Enter, the commands are sent to the Console Pane and executed correctly. However, scrolling up in the commands, and in the History Pane, we don't get the code. Instead, we get
source("~/.active-rstudio-document", echo=TRUE)
@kevinushey Is this expected? Asking here before opening a bug, in case it's what should happen.
Activity
ronblum commentedon Sep 21, 2018
Are you looking for something similar to when multiple lines are entered at once in the console?
x <- 11hadley commentedon Sep 21, 2018
Yes, exactly!
jmcphers commentedon Sep 21, 2018
It works this way because we need R to evaluate each line individually -- that way we can avoid sending further lines to R when an error occurs, and can also track the production of artifacts such as plots to their originating lines.
We might be able to paper over this in the history so that it still looks like all of the lines went to R in one go.
ClaytonJY commentedon Sep 25, 2018
@jmcphers could a single expression at least be one blob in the history, as it is for non-Rmd code? E.g. an expression like
appears in history line-by-line when run from an Rmd (whether the whole chunk or ctrl-enter), but is one history entry when run from an R script (ctrl-enter, shift-enter, etc) or the console as demonstrated above.
I think the expression-specific behavior is a regression, as at some point in the past the expressions were combined in history, though I couldn't tell you how long ago that was; at least 3 months, possibly much longer, and I tend to run latest-release versions.
pqmatagi commentedon Jan 2, 2020
Belated vote for a change here.
Perhaps a separate issue, but for executing a selection from within a code chunk, I definitely think the approach for source files should be followed, i.e. a single blob as noted above. This use case is much more likely to involve subsequent history fiddling by the user than the full chunk, I suspect. And it's just plain inconsistent.
Even in the complete chunk case, executing top level expression by expression makes much more sense than line by line, if the parsing can be done to allow this. (No error or artifact linking downside, is there?)
Note that line by line history with incomplete statements is not only pretty useless for experimental modifications of the executed code from the console, it makes it painful to navigate to other parts of the history that may or may not have come from the notebook code.
I also feel like there's been a regression, though I can't validate that (and wasn't there multi-line functionality in the History pane at one point?).
MarcoPortmann commentedon Jan 10, 2020
For quite some time I thought something was fundamentally wrong with the debugging options of RStudio. From another R IDE, I was used that the following code would stop at
Var1 <- MyFun(Var1)such that Var1 finally takes the value 12 and not 14 when the code is send using ctrl+enter.I am clearly in favour of sending the text selection in the editor as a block and not line by line. It would have great advantages for debugging, since commands after buggy code wouldn't spoil any objects.
jmcphers commentedon Mar 30, 2020
Another vote for this over in #4503.
pqmatagi commentedon Apr 14, 2020
To me, having different history behavior for "execute selection", depending on whether the selection is in a .Rmd file or a .R file, is a bug. Making them consistent is not an enhancement, it's how it should always have worked. If you feel this is different from the original issue posted, I'm happy to open a new one!
renozao commentedon Apr 27, 2020
This issue makes writing analysis notebooks very cumbersome in practice. A fix would be greatly appreciated.
A workaround is to write the notebook as an R script and process them with
rmarkdown::render(~ spin + knitr), but then one does not get all the other features of Rmd notebooks (chunk submission, embedded graphs, etc...).pqmatagi commentedon Apr 29, 2021
Thanks for reopening!
Please keep in mind that despite the OP topic, there are multiple scenarios, as mentioned in the other comments:
I believe 2. and 3. should behave like they do for a .R file (from the console history point of view, at least). For 1. I would prefer the @ClaytonJY suggestion of grouping expression by expression (i.e. act as though 2. was used for all the chunk code at once), but the @hadley ask of the whole chunk as a single history item would be an improvement.
Related issue, perhaps requires a separate item, but it would be nice to think this would also fix it: it seems like we lost grouped line selection in the History pane at some point in the product history. A user almost never wants to select a single line from a multi-line expression in the History pane to copy to source or console, but to get the whole expression requires extending the selection with shift-click or some such operation. Annoying.
bigO6377 commentedon Jan 15, 2022
Hey guys, is there any update/fix to these issues? Namely:
Using the following version/OS
brooksambrose commentedon Aug 23, 2022
I would consider it a feature if any solution here would also prevent subsequent lines from being fed to an empty
readlinecommand that is waiting for user input. For example, we might expect the following behavior when sourcing this block:Yet running it as a chunk yields:
teecrow commentedon Jul 18, 2023
I agree with @pqmatagi and others re: the issue with the console history after running a selection from a code chunk in rmarkdown RMD or quarto QMD files. Is this "selection" problem considered the same as the "Full chunk" problem and thus being tracked in this Issue? I often use Ctrl-Enter to run a multi-line operation (joined by pipes) in a chunk, and this more or less ruins the console history because each individual line (i.e., that which is captured by the history) is useless on its own. Would be nice to see consistent behavior with .R files for this, since it's highly useful for tinkering in interactive mode.
ronblum commentedon Oct 29, 2024
Verified in RStudio Desktop 2024.11.0-daily+331 on Windows 11.
Used variations of the examples above, and guidance from the QA notes:
Checked both Console Pane, which groups the chunks, and the History Pane, which treats lines separately. Checked both Rmd and Qmd. With "run all", the chunks are correctly treated as separate blocks, not all as one.
Question: I found interesting behavior with R scripts. When using Ctrl-Shift-Enter, the commands are sent to the Console Pane and executed correctly. However, scrolling up in the commands, and in the History Pane, we don't get the code. Instead, we get
@kevinushey Is this expected? Asking here before opening a bug, in case it's what should happen.
ronblum commentedon Oct 29, 2024
Moving to "Ready" because of the question; otherwise, this issue is fixed.
kevinushey commentedon Oct 29, 2024
That is expected; it's an artifact of how Ctrl + Shift + Enter works.