Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What cause format change when copy and paste in rstudio?

Tags:

r

rstudio

#sample select
sample_frac(mydata,n%)#random select n% sample

##############data review####

Just copy above code into rstudio script, you will find 2 more tab added to the last line.
What cause it?

like image 741
kittygirl Avatar asked Jun 30 '17 02:06

kittygirl


1 Answers

Edit

As mentioned by @Jay in the comments, the n% in the command is treated as a function and since it is not complete it indents the next line.

To further confirm, try with df %in% in the script or df >%> and hit enter to see the cursor goes to the next line with an indent.

To avoid that just complete the function there.

sample_frac(mydata,n)

OR

sample_frac(mydata, n %% somenumber)

whatever you are trying to do and it should be fine.

Original Answer

It did add 2 tab spaces in the code when pasting in the RStudio script. I tried to paste the same text in my notes, Pycharm editor but it did not add any extra tabs there. So it was sure that this is a RStudio issue.

It turns out it is the indentation settings in RStudio which is responsible for this. To change that:

Go to Tools -> Global Options. Click on the Code option on the left. You'll see this :

enter image description here

Uncheck Auto-indent code after paste

enter image description here

and click on OK.

Now try to paste the same text. Should be resolved.

like image 161
Ronak Shah Avatar answered Nov 08 '22 05:11

Ronak Shah