-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Execute Script window statement by statement rather than line by line #8551
Execute Script window statement by statement rather than line by line #8551
Conversation
TODO (please ignore, note for self):
If statement has newline, then output is as expected. |
…bracket character
@rdstern |
@lloyddewit many thanks - will do |
@lloyddewit I was initially confused about what runs easily and what is strict? I think I have now found the reasons, see below, why one script runs fine and a seemingly similar one does not. I found 2 reasons anyway, and wonder if they might be possible (even easy?) to fix?! This first one runs fine with the cursor at the start of each line and pressing run. Then the second starts - to my mind - identically, but gives me this: But that is when I try to run the first line, that just gives the library command? I think there must be some checking of the whole code, before anything is run? Then something in some codes affects all the imterpretation. Because when I delete the last half - so after the command vc(lmn), (so after about line 50) then the initial commands seem to run ok? Aha I note I deleted the section that starts with I think I have the problem(s) isolated. There are 2 in this second code:
And this is the second script: I must be missing something. Is there something in the whole script that is being checked and affects how anything is processed in that script?
|
@rdstern yes, you are correct. In order to execute statement-by-statement using ctrl-enter, the whole script needs to be parsed by RScript. If any part of the script can't be parsed, then the user needs to select the part to be run or the user needs to select Run All. I can see that this could be annoying. To change this, I would need to spend time on improving the back up system. I would prefer to invest the time in RScript so that the backup system is required less and less (hopefully at one point never or extremely rarely). The question is: could the current approach be merged as-is or would you prefer to wait for a new RScript version before merging? |
@lloyddewit I am a believer in merging as soon as possible, particularly as I don't see any obvious regression here in other, seemingly unrelated parts of R-Instat. Getting to the practical issues I will be happy for this one to be merged and then just need to add the documentation on detecting scripts with possible problems and then describing the work-arounds in those cases. I see there will be two types of work around. An example of b) used to be when there was I would at least be keen to know what causes b) and minimise or eliminate those. Perhaps the comma at the start of a multiline is still there, or is that now ok, if I mark the whole section? I am not even asking for that, before we merge. Then I could recommend that users "test" a script initially by trying the library command - as I did. If that is ok then all is simple. If not, then they can either run in chunks, or comment out the offending sections. That's all fine! So I tried a script with a single problem. It then gave a message - as I expected - with this line:
I pressed OK and it seems ok then. So this problem sort of becomes an a) rather than a b) above. So perhaps fine already!? But it didn't give output, so I am not sure if it ran? Finally an unrelated question. I have been commenting out different blocks of code - so putting a # at the start of multiple lines. Is there a way of doing that easily on a block - perhaps via a right-click? It would be an R-Instat of this:
|
@rdstern Thank you for the positive feedback!
Some code only works using RScript (e.g. There may also be some R statements that do not work using either approach. I think these are mainly related to how R-Instat handles the output. An example is lloyddewit/RScript#17. As I mentioned before, I think the best approach is to fix these problems in RScript so that the heuristics approach is needed less and less.
I think this works using both approaches, do you have a test case that fails?
This only currently works using the heuristics approach. There is no output because it is an assignment statement. I raised #8568 for commenting blocks of code, and added it to the list in #7989. I hope this makes sense, let me know if you have any questions. |
@rdstern
and whatever else you can think of ... P.S. Code that can't be parsed by RScript is covered here. Fixing this will be my next task. If anything is missing, then please let me know |
@rdstern I fixed the issue with commas inside square bracket operators (e.g. |
@N-thony Thank you for reporting. I think you may be running an older version of this branch. The output from the latest version is shown below. I think this is correct. If I misunderstood, then please let me know. |
@lloyddewit great that seems to work fine now. I am really enjoying running the script statement by statement, through just pressing the Run repeatedly. The script below has a number of items of interest! So I have 2 questions now:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Patowhiz hope you can check this. It is still "work in progress" but good for you to examine, and then consider the remaining work as a new later pull request.
@rdstern Thank you for testing.
No, this is already requested in issue #7989.
I tested and, as far as I can see, all the comments are displayed in the output window. The only exception is when a comment is not followed by an executable statement (i.e. comments at the end of the script); or when only a comment (with no executable R script) is selected and run. These comments are ignored (deliberate design choice). Would you like comments without statements to also be sent to the Output window? If I misunderstood anything, then please let me know. |
@lloyddewit you seem to imply that would be easy to do. When I mark and run a comment then yes, it would be great if it could be sent to the output window. Meantime I am happy with your dummy command. So here is an example with comments at the end of lines: Here are 2 lines from this:
The first, is an assignment and the comment is in the output window.
|
@rdstern |
@lloyddewit after our discussion it is clear I made a mistake on that point, i.e. on the comment not appearing sometimes when it was at the end of an executable line. I had expected it to appear after the result. Instead it does appear, but above where I looked, as part of the command line, and that is quite right! |
@rdstern You reported that comments at the end of scripts, that are not associated with any R statement, are not shown in the output window. On 17 Oct, you gave this example: I have now changed this to what you requested. You can use ctrl-enter to execute comments appended to a script; or you can highlight/execute just a comment. Run All will also show any final script comments in the output window. I also fixed the bug shown below. Please could you test/approve? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Patowhiz this still all seems good.
Note the issue of the log window opening is fixed in Antoine's pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lloyddewit thanks for this.
Below are my few requests and suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lloyddewit thanks for addressing my suggestions.
Once you refactor the functions to avoid the duplication we can merge.
@Patowhiz Thanks. I replaced some of the duplicated code with shared private functions. I tried to refactor out more of the duplicated code but found that to make it work, I would need to significantly refactor the existing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rdstern @lloyddewit give me more time to look into this. |
Replaces PR #8494.
Fixes #7014.
Fixes partially #7989 (allow
=
to be used as an assignment operator).Fixes partially #8533 (show R code comments in output window, new pipe operator and multi-line statement; plus third block of code).
This change will make 'ctrl-enter' execute the R statement at the cursor (rather than just the line), this should fix the current bugs with multi-line statements.
Ongoing, not yet ready for test/review.