How do I check current variables when running a project in RStudio? - r

Is there a way to check currently set variables and their corresponding values when running a project in RStudio?
This is for debugging purposes and am seeking an alternative to the browser() command. The browser command does not always work it seems.

I wouldn't necessarily say it's a debugging tool, and I honestly like working with browser(), but are you aware of the environment tab? Sound exactly like what you are describing. It's usually a tab in the pane alongside 'history', 'connections' and 'git' and lists e.g. variable names and values and allows you to inspect them.

Related

How can I get my personal notes within the console to change color?

Console My ## tag is not changing color, what can I do to change that?
I have tried looking for a solution in my settings, but there has been no luck.
The console isn't a place to make and keep notes. The console isn't something that gets saved, so if you are trying to add notes to a script, you probably want to create a new script.
In R itself, I am not sure if or how you have notes (in scripts) change colors, but this happens automatically in some "Integrated Development Environments (IDE)", such as RStudio. For learning how to use R, I would recommend downloading RStudio. When you create a script there, your comments starting with # will automatically be a different color than code.

How do I turn off report generation in OpenMDAO 3.17?

How can I turn of the report generation in OpenMDAO 3.17?
I've tried add the following code to the top of my script:
import os
os.environ['OPENMDAO_REPORTS'] = 'none'
In place of 'none', I've also tried '0', 'false', and 'off' as mentioned here in the OpenMDAO documentation. This is the only way I've seen to change the environment variables.
Are there other ways to permanently change them such as through the command prompt? I'm relatively new to python, so spelling it out for me would be helpful.
Also, I know this is a repost, but I don't have enough points to add a comment to that post. So I've had to create a new post. That post also mentioned a PR, but the summary indicates the report generation was only fixed for some Dymos functionality.
When you change the setting via a python script (as your question shows) you are only changing it for that active python session. Not permenantly.
You don't say whether you're on windows or linux, which changes the specific method you would use to achieve your goal; Generally though, you can set the environment variable so that its given whenever you open a terminal. This will have the effect you desire.
On windows, you set environment variables via a small system GUI. On linux you change them by adding a line to a config file (usually .bashrc). On Mac the file name is sometimes .bash_profile or .profile.
I couldn't get them to switch off via environmental variables, whether setting them in the python script or from the terminal, but when creating the problem this worked
p = om.Problem(model=om.Group(), reports=False)

Is it possible to use the same key-binding for two different packages based on the file extension?

I use the atom-runner package, which runs scripts when I click alt+x:
Now, I also installed the gpp-compiler package, which runs c++ files when I click F5:
It is confusing to have two different key-bindings for running. I would like to use alt+x both for gpp-compiler and for atom-runner, based on the file: if it's a c/c++ file then run gpp-compiler, otherwise run atom-runner.
Is this possible?
You are in luck. I was doing something similar to this recently and thought that this could be done.
I've made an Atom package to do what you're looking for. You can find it at https://atom.io/packages/multi-hotkey. The default hotkey is Ctrl-M.
Currently only one hotkey is possible, but with customization available for four different user-inputted file extensions and corresponding commands, and a final command for anything not matching the preceding extensions.

Start shiny app with input on shiny-server

My problem is as follows: Think of a shiny-app that handles a text input and presents results for this input. However, I want to limit the possibilities of my customers in a sense, that they can not give the text input manually (due to third-party-API-rate-limits) but only once externally. I retrieve the necessary input in a survey externally and I then want to redirect to my app with the input already given (so that they should not be able to play around with different other inputs).
So basically my question boils down to:
"How can I handle the input to a shiny app through a URL."
Let's say my app runs on
1.1.1.1:3838
which displays my app when I open it in a browser. Could I e.g. transform my app to handle URL-requests such as
1.1.1.1:3838/exampletext
(where 1.1.1.1 represents an IP Address) in a way that it then can process "exampletext" in its calculations and displays already prepared results (without the need of a textInput()-field)
I set up a shiny-server on an AWS EC2 instance but I am struggling to find any recommendations on how to build the infrastructure. I first intended to start a new app for each input in a bash script such as:
./app.R exampletext
and process it in the shiny app then like that:
args <- commandArgs(trailingOnly=TRUE)
textInput <- args[1]
However, I think there should be more clever ways to do this with a shiny app/on a shiny-server (apart from the fact that I don't have a real idea how this could really work out). Should I maybe consider a bash script to help me process the input and automatically start a script? In any case, I would be grateful if someone could at least provide me with some keywords to look for the matter appropriately. Thank you!
EDIT1: As proposed by #jyjek and also in this thread:
How do you pass parameters to a shiny app via URL. I could use an observer object that processes any changes in the URL to other objects. This solved the basic foundations of my problem, however, I could use a more static approach as my main goal is to create a non-changeable input. Therefore it is not necessary for me to adapt to changes in the URL, I rather prefer to give once a URL that should not be changeable.

Do any R IDEs support conditional breakpoints?

Which, if any, R IDEs (e.g. StatET, Revolution R, RStudio, ESS, NppToR, others) support conditional breakpoints?
This is available via bp in the debug package, or via an additional bit of code that invokes browser() based on a condition. However, it can be more efficient to be able to toggle a particular line # and quickly enter a conditional breakpoint for that particular line, without having additional code or console activities.
Note 1. I've searched a bit for these, and it seems that conditional breakpoints are not available in RStudio, and I think the same may be true for StatET. There appears to be support in ESS (see this page), though I'm not yet familiar with ess-tracebug and whether it's easy to use. It also seems that this works only for older versions of ESS; I'm not yet familiar with functionality for more recent versions.
Update 1. I'm selecting an answer (the only one - Andrie's). The question was answerable regarding whether any IDE supports conditional breakpoints, and, fortunately, Andrie has demonstrated that there exists a solution. I remain interested in any other IDEs that support this, though Eclipse is good enough for now. (At the moment, I prefer Rstudio, but this is already in their feature request list.) If anyone has expertise in ESS and can demonstrate that functionality, I'm sure it will benefit others who happen upon this question.
Yes, this is possible with Eclipse + StatET 2.0 in R 2.14-1.
Eclipse supports conditional debugging, and StatET 2.0 supports visual debugging (as long as you have a fairly recent version of R.)
Assuming you know your way around Eclipse, do the following:
Start a debugging session in Eclipse (i.e. invoke a Debug configuration, not a Run configuration)
Set a breakpoint in your code
Open a Debug perspective
Run your code
With the debug perspective open, you will have a pane that contains tabs for Variables / Breakpoints. In the breakpoints tab, select your breakpoint, then click the Conditional / Expression tickbox and enter your condition.
In searching for this answer, I found the following pages helpful:
Download and install StatET
How to start a debugging session in StatET
How to set a conditional breakpoint in Eclipse
There is a little trick to set a conditional breakpoint in rstudio:
for(i in 1:10){
if(i==5){
print("set the breakpoint at this line by shift+f9")
}
i*i
}
The only drawback is you need to add some extra code
The preview release of RStudio v0.98 has this feature:
http://www.rstudio.com/ide/docs/debugging/overview
Only drawback is your function should be in the same file with your main code if you want to set a breakpoint in your function.

Resources