Add shortcut to section of long R script? - r

I have a very long script with more than 5000 lines and I was wondering if I could add shortcuts to sections of the script.
I have separated my script into validation, prediction and figures. I would like to have little shortcut/link at the beginning of the script, so someone that wants to have a look at a part of my script doesn't have to scroll down.
Does anybody knows if such things exist?

In RStudio, if you put four #'s on each side of a comment on its own line, RStudio will mark it as a section that can be navigated to by clicking on it at the bottom of the source code window. It should read 'Top Level' by default.
Example:
#### Calculate standard deviation and moving average ####

Related

how to remove constant line from point line series?

I'm using constant lines to show a particular event for the graph and now I want to remove that particular event. I'm using constantline.dispose method but It's not working properly. lines are not getting removed after calling dispose function.
ConstantLine.dispose() should do the trick, and seems to work in the official interactive examples gallery (LCJS v.3.4.0).
If it is not working for you, please add some example code or pictures & description of desired and actual behaviours.

Adjust Rmarkdown's inline chunk output - increase no. of columns displayed?

This is a workflow related question. I'm trying out working only (or mostly) in the Rmarkdown source window with the options set to "Chunk output inline". So with R open, there is just one big window -The environment, Console and File windows being minimized.
My question: Is there some option to change the number of columns displayed? I want to increase the numbers of columns visible without scrolling (see screenshot below), and since there is enough space I think it should be possible to display more of them.
Many thanks!
Solution: There is an option. Just add cols.print = 12 (or whatever number you want) to global options.
Also, people might find this 'manual' on markdown useful: https://bookdown.org/yihui/rmarkdown/html-document.html#paged-printing

Make Octave set a figure to be the active window (come to the "front of the screen")

When Octave draws a plot, I would like it to set that to be the active window automatically, so that it becomes visible and I don't have to click back and forth between windows to see if the code and plot have finished. Is this possible? Since it would require reaching outside of Octave and controlling the OS, I'm not sure; it depends on whether or not that capability is part of Octave but I haven't found a reference for it yet.
I can always tell Octave to close the figure before opening a new one in the code, but that could prevent me from drawing multiple plots on the same axes, and it would require me to code that command in every time. It would be nice if there were a direct way just to bring the plot to be visible and take dominance over other windows.
EDIT: Somehow, although I noted that Octave would be required to control the OS to achieve this, I completely forgot to mention what that was... I'm running Windows 10 with the default window manager; I believe that would be the Desktop Window Manager.
When you plot something on a figure (whether you specify the figure you're plotting to within the plot command explicitly or simply let it plot into the currently active figure implicitly), this does not automatically raise the figure window to the forefront.
To do so, call the figure again using the figure function, along with the handle that you want to raise.
Alternatively, if you're sure that the figure you want to raise is the currently active one, you can simply use the shg command (which is effectively equivalent to figure(gcf))
E.g.
Fig1 = figure; % (or figure(1) if you want to be explicit)
Fig2 = figure; % (or figure(2) if you want to be explicit)
figure(Fig1); plot(1:10); % raise Fig1 to the forefront, and plot.
PS: Note that there was a bug affecting this behaviour until recently (coincidentally submitted by yours truly :p See https://savannah.gnu.org/bugs/?45943 ). This is fixed in the latest version of octave though (i.e. 5.1.0)

Is there a way to save and quickly reopen surface plots in IDL (Interactive Data Language)?

I was wondering if there is a way to save surface plots in IDL in a way that is convenient to reopen them. As far as I am aware there are only two ways of doing this:
The first way is to save your surface plot as an image e.g. png. The trouble with this is that the viewing angle is fixed and you can no longer drag with the mouse to rotate the surface plot.
The second way is to save the code which generates the plot. Trouble with this is the code often generates loads of plots which are usually just saved as images.
I would like something you can open easily and which opens the surface plot as though you had just run the code to generate it. So that you are free to rotate it by dragging the mouse.
Does this exist?
I only have IDL version 8.3.
If you 'Generate code/save data' (either via the toolbar at the bottom of the window or via the generateCode method with the SAVEDATA keyword), you get a .sav file that contains your plot. Either use the code generated to restore it, or use the generated code as an example to write your own.

Is there a way to replace the legend or axis without redrawing the whole plot?

Sometimes I will place a legend at a particular location on the plot, let's say topright, and then I see that it covers an important part of the plot. Is there a way I can switch it to topleft or some other place without having to run all the other commands first? Sometimes I have the same problem with the axes, I misspell a word and then I have to issue all the commands again.
I eventually place everything in an R script which means this becomes less of a problem, but sometimes I want to quickly test something in console. Please tell me I have overlooked a basic command that does this.
There is no such thing, but you're on the right track - a script is definitely the way to go. I would also recommend R Studio, a free R IDE, which gives you several displays, one for scripts, one for the console, one for your plots - it's great! It makes working with scripts as easy as interacting with the traditional R console.
As Gabriel told you, a script is the best way. However, the following link could help you:
Using Inkscape to Post-edit Labels in R Graphs

Resources