retrieving a line of code after pressing the down-arrow key - r

If I type a line of R code at the cursor and press 'Enter' I can immediately retrieve that code by pressing the up-arrow key once. However, if I am typing a line of code and accidentally press the down-arrow key once then that line of code disappears and I cannot retrieve it. This is a minor, but ever-present annoyance, most frustrating when typing data into a vector.
Is there a way to retrieve a line of code after accidentally pressing the down-arrow key?
I am using a Windows machine and the R GUI found on my desktop immediately after installation... ...I think one of the questions during installation is whether I want a short-cut on my desktop, and I select 'yes'.

this is completely dependent on the GUI. I believe (but am not certain) that RStudio, for example, preserves what you have typed.
While not a direct solution, what might be helpful is to use edit in an external window. I dont use windows, but I suspect if you hit ctrl+n you will get an editor in which you can then use F5 or ctrl+R to execute that specific line.
Personally, I use Sublime Text 2, and cmd+enter gets my code executed at the console

I found that if I open R and click File then New Script in the R menu an editor will open. I can type a line of R code in that editor. Then I can highlight that line of code and press Ctrl+R, as mentioned in Ricardo Saporta's answer and djhurio's comment. By pressing Ctrl+R that line of R code will execute. The line of R code remains visible in the editor and seems safe from being lost even if I accidentally hit the down-arrow key.
Hopefully this builds on Ricardo Saporta's answer enough to warrant being posted as another answer, although I would not have figured this out without Ricardo's and djhurio's help.
P.S.
In retrospect, I see now this is what Ricardo meant in his second comment beneath his answer.

Related

R : Using shortcuts to insert operators writes to a different file

I'm sharing a small but annoying issue that sometimes pops up when I'm using shortcuts to insert operators while working on a markdown file in R : the operator either does not get written, or even worse gets written on another file.
So let's say I am working on the file "report.rmd", and I want to insert the pipe operator using Ctrl+Maj+M, or the assignment operator using "Alt+-", and I have the file "test.R" opened. Well, I therefore type the aforementioned shortcuts and...nothing happens on my markdown file. But some nice operators that had nothing to do there get written on my test.R file.
The only way I found to solve this problem is to close and reopen RStudio (restarting unfortunately doesn't solve the issue).
While this is quite a minor problem, it's incredibly annoying. Did it ever happen to anyone of you, and if so do you know where it comes from and how to solve it?
Edit:
Although I am still running into this issue (without being able to reproduce it consistently) I came into a somewhat lighter solution. Instead of restarting R, simply closing all tabs (closing just the problematic one doesn't work) solves the problem. I hope this helps narrowing down the possible origins of the problem.
Short Answer
re-define the key combo to Ctrl+Shift+ \ , assuming this does not create a conflict
Background
I've had a similar problem for a while, too. In my case, the shortcut never works. I can not find the source. I even found a conflict with Ctrl+Shift+M assigned to 2 Editor functions.
Image:Screen Capture 2 conflicting hotkey assignments
However, a simple key reassignment of the one that is not the pipe operator ("Expand to Matching")
Image:screen capture showing the hotkey conflict solveddidn't solve the issue in my case.
Solution
Here's what did the job for me
I managed to assign a different combo (that hasn't been assigned yet) and that is comfortable enough in the sense of its location on the keyboard
go to Tools → Modify Keyboard Shortcuts...
In the filter box, write "Pipe"
Direct the cursor to the text box showing the current shortcut, and press the new combo (e.g. Ctrl+Shift+ \ ), then Enter.
Remember to hit Apply
Make sure the new Combo isn't a duplicate of another command, by going back to step 1 and sorting the list by Shortcut, then scrolling down to find your new one. if there is an ovelap, consider changing one of them.

Jupyter-lab: go to previously active cell

Does JupyterLab support a functionality to jump to previously selected or active cell?
Use case #1: sometimes I accidentally hit "Home" or "End" while in Command mode (thinking that I am in Editing mode) and I jump to the very top of my notebook. Then I need to find the place where I was doing the editing.
Use case #2: Sometimes its convenient to do the above on purpose. Jump to the bottom, run a side calculation and then come back to the previously active cell to continue my main line coding.
It would also be nice to assign a shortcut to this command if it exists. I've looked through this github thread, but have not found an appropriate command.

orientdb-community-2.1.12 history tab

Is there any way that I can help get the "Search in history" dialog box in the orientdb-community-2.1.12 web interface to work? When I type a word into it, for instance "select" it returns "Warning You are clearing history. Are you sure?" just as if you clicked on the trash can.
I would be very happy to register this as a bug if it really is.
Sincerely,
Flint
One work around is to run the command line version of orientdb. You do this by starting the console.sh program. This keeps a shell history, and while it is not so convenient to cut and paste between windows, heck. it works.
To get a history file, reasonable way is to grep through:
orientdb/orientdb-community-2.1.12/bin/.orientdb_history
Regards,
Flint

RStudio view functions in the environment

Apologies if this is not an appropriate question, or if it is answered elsewhere, but I have done quite a bit of searching and I think I must be searching for the wrong thing...
I'm sure that in R Studio, you used to be able to click on a function which is in the Environment, to view it and see what it does. It was really easy and convenient. It doesn't work anymore. Is there another way to do this just by clicking, or is the only option to run the name of the function to get it to print in the console? I'm sure that it used to give a pop-up window where you could see the syntax highlighting and things too, which was really useful :(
I think it still works, at least in my version it does. On the upper right panel, on the top, you have a pull-down menu entitled "Global Environment". Click on this to select the package that you have loaded (or select package:base for the functions of base R), scroll down to "Functions" (there is usually a long list of "Values" before you reach that point), then click on the icon on the right side of the function that you want to see. The source code is opened in the viewer.
If this is too long a sequence to click, you can alternatively just type View(foo)in the RStudio console to display the source code of the function foo.

Tidying up history in RStudio to document an analysis

I am doing some analysis in Rstudio and at the moment - as I am refreshing my knowledge of R after a few decades away from S - this involves writing lots of one-liner statements which operate on test datasets, and then inspecting/testing the output, then finally scaling it up when I've checked all the little bits work.
So my history is full of syntax errors and similar. But I am making progress every time I work, and each time I work there are statements that worked, that I want to save, in order to document the bits of the session that are worth saving. Is there any established way of extracting these from my history for re-use, in RStudio? Should I just scroll through after each session and copy and paste them into a textfile with a word processor? Or is there something more clever than that that I can do, staying within RStudio?
The easiest way to see your history, is to hit Ctrl-4 and that will bring up the history window. You can copy this to source and then edit it, or where ever. However, for what you are doing it is probably better to edit directly into a source window.
The setup I use is to have a script window open, and use ctrl-enter to run the current line.
To make this easier go into Tools>Options>Code Editing and ensure that "focus console after executing from source" is unchecked and your cursor will stay in the script after the line is executed.
You can now type your lines and edit them until they do what you want, then move on to the next when it works. Once you get to the end you have built up your script already. Also since your "history" is just their in front of you, it is much easier to skip back to older lines and rerun or modify them. If you want to run a block of code, simply highlight the block and hit ctrl-enter.
In the history panel in RStudio (top right panel), you can click "send to source" and it will copy the line you have selected over to whatever .R file you have open in the top left panel.

Resources