How to print in r source stops - r

have a code that calls different codes inside it with source function. if an error occurs when running a source i would like to save the information of the error that appears but im not being able to do it. Does anyone know if this is possible? Thanks!

Did you try traceback() after the error occurred? You can also set it in options(error = traceback). I think RStudio IDE provides tracebacks by default.

Related

OpenAI Gym - Env.Render() function returning "Display surface quit"

A screenshot of my code with error
I am following the tutorial seen at https://www.youtube.com/watch?v=7SVv07QXO5M&ab_channel=HackersRealm
The exact code I am following is here: https://github.com/aswintechguy/Reinforcement-Learning-Projects/blob/main/Cartpole%20Balance%20-%20OpenAI%20Gym%20-%20Reinforcement%20Learning/CartPole%20Balance%20-%20OpenAI%20Gym%20-%20Reinforcement%20Learning.ipynb
Not sure what I am doing wrong but the guy doing the tutorial had no issues so I'm not sure how to troubleshoot this. I'm also doing this in a Jupyter Notebook. Any ideas what I might be doing wrong here?
I have seen similar error, in my case i got this error when i ran the env.close() and tried running again, i'm suspecting, this was the reason for my error, because once env.close() has been called there is no environment to perform rest of the operations so I had to re-run the cell to create the environment to try it again. Im assuming this may have been your case.
Try running the cell with make environment and retry the cell which throws u the error.

What is this error in RStudio: "breakpoints will be activated when the file or function is finished executing"?

I am trying to set a break point inside a function from a package I wrote. I am unsuccessful when clicking next to the line number in Rstudio, the error message looks like:
I am not executing anything. Reloading the package did not help either. What is this error and what can I do about it?
Check out this documentation from RStudio that explains what to do.
Basically, make sure you save your R file, then click the Source button on the toolbar:
Your breakpoint should then turn from a hollow red circle to a full one.
Usually running rm(list=ls()) will do the job.

How do I get pretty error messages in RStudio?

When working in RStudio (version 0.99.482 and 1.0.136), if I source a file and an error occur I just get the error message without any context. If the file is longer than a few lines of code, that informaiton is largely useless. What I want to know when an error occurs is the following:
What function threw the error? Preferably what function I called from my script, not something burried deep inside a package.
On what line of my file did the error occur?
This seems like a very basic thing for a scripting language to do, but yet I am unable to find an easy solution. Yes, I am aware of the traceback() function, but (a) it is a hassle to call it every time there is an error, and (b) the output is massive and not that helpful.

Print list of all error messages after running an R script

Apologies if there is an obvious answer to this question, but I haven't found one.
All I'm looking for is the error equivalent of warnings() - I want to run a script, then get a list of all the errors that occurred when running the script.
Have had a look at traceback() and it seems like it might do what I want - the help file says "The default display is of the stack of the last uncaught error" - but can't figure out how to make it return all uncaught errors rather than just the last one.
My suggestion would be, save the script (e.g. script.R) then run the whole script using source('script.R'). This will stop at every error. If you just want to see if errors exist, this will be a good way to do it.

Slow or stacking file.choose() in R

If I have more data loaded in R I'm having difficulties with opening and choosing new file via file.choose() and later upload via read.csv(), but I would not get to that point since the file.choose function stacks and the R "crushes" and reports something like "unidentified error occurred and that the R must restart".
I'm using RStudio and running this on Windows 7. The hardware is up to date.
Could someone point me on why this is happing and what would be a remedy against this. Are there other options to select file? I know I can insert the path right into the read.csv command, but the (file is different every time).
EDIT:
The error just happened again. I can not reproduce the error so it happens rather only with high likelihood if the conditions for it are met.
The error reads as: R Session Aborted.R encountered fatal error. The session was terminated. And in window: "Start New Session".
EDIT 2:
I would just rephrase my question. The question is whether there is other option like command or package that deals with choosing a file. [file.choose()]
The error can not be reproduced and hence I can not expect someone gives reasonable comment on this. But if this occurred someone in the past and solved it, I would like to hear about it. Thanks.
EDIT 3: Further to the error. I have spotted just now sentence in red in Console: Error: Unable to provide connection with R

Resources