RStudio - Change number of spaces in a tab - r

I spent at least an hour trying to figure out how to change the number of spaces RStudio uses for a tab. To me using only 2 makes it extremely difficult to read the code. So after finally figuring it out, I decided to post this to save others the headache.

I've seen this question asked many times with various round about and strange answers but it turns out the answer is simple.
First go to "Tools">"Global Options"> on the side bar select "Code" and change "Tab Width"
THEN next is the step everyone is missing. The option above will be overwritten if you've already started the file. So next go to "Tools">"Project Options"> on the side bar select "Code Editing" and change "Tab Width" again. I'm not actually for sure the first step was needed but it may be because that's what I did.
Finally, you simply delete all the code and paste it, and it magically has the new number of spaces! Took me a long time to figure that out and was unable to find anything with such an easy solution, so I wrote this.

Related

Disable Jupyter Notebook cell only for whole notebook run

I don't know if it is possible, but I have a Jupyter notebook where I'd like to disable some cells in case of a whole run.
That is, 'Run All' would jump over these cells and not trigger them, but they could still be used if ran alone (e.g. with Ctrl+Enter) without changing the code.
I know %%script false --no-raise-error does the trick, but you need to manually change a constant to re-enable the cells when you need them. Ideally, I'd not have to change anything in the code.
Thanks in advance!
Your question resembles another question on here that I've answered recently. It's not the same question but I think my solution to that one actually works better for you. Here's the link to it and I hope it helps: https://stackoverflow.com/a/73978254/16264178
(PS I previously just copy-pasted my answer to the other question to here and that got flagged by a moderator. He was right that that wasn't best practice (answering different questions with the same answer verbatim). The recommendation though was to flag this thread as a duplicate of the other, which it isn't really. They're similar questions but my suggestion was a fairly imperfect solution to the other query, whereas I think it applies very well to the question in this thread. That's why I reposted my answer here with a link to the other one. That was the best thing I could see to do but people should feel free to enlighten me if they know better)

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.

Gamemaker Studio 2: My character isn't transitioning properly throughout rooms

I've followed a specific course by Aidan (as shown here: https://www.youtube.com/watch?v=evkFHHNp0-Q&list=PLwG2Q399ulV3TyEWodJYrje3KsxvIxBv1) for my Gamemaker Studio 2 video game, and I didn't have any issues until I realized when I reentered a room my character disappeared? My character normally transitions from Room1 to Room2 pretty easily, but when I want to go back to Room 2 from Room 1, the character isn't there. I tried rewatching videos where he explains "warp points" as well as his other videos, and the solution to my issue doesn't seem to come up.
I set my character to "persistent" by setting it in the creation code to be true, as well as check-marking the box on the actual object, but it still doesn't work. Any help would be greatly appreciated!
EDIT: I realize there is a similar question another user asked(Gamemaker Studio 2: My character won’t transition through rooms), and I tried doing what they suggested but it still doesn't seem to be working. I don't think the issue is that the character won't transition through the rooms, I believe that it can't transition multiple times without something going wrong.

R Studio - How to change the name of a dataframe in a script by one click?

I have a pretty simple question, I googled it, but I cant find anything, probably I am using the wrong words.
I am using R-Studio and I want to change the name of my dataframe for my whole script. I used that name 20-30 times and I dont want to change everything manually. I remember that our teacher showed us a trick once. When you click on the name of the dataframe you want to change, every entry in the script is marked with a blue window.
How does that work? What do I have to do that I can rename all these entries by changing only one of them?

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