3

I use spaces to indent but RStudio always converts spaces into tabs. This is even though I have the "Insert spaces for tab" global option selected. Drives me batty!

Here's my settings in case I'm overlooking something.

Thanks in advance!

mowshowitz
  • 69
  • 6
  • 1
    Project options override global options. Maybe you have something different there? – user2554330 Jan 15 '18 at 20:10
  • Oh, possibly...when you say "project options" are you referring to options set when using RStudio Projects? If so, I don't know if that's it since this behavior happens even when I open a new instance of RStudio. But you may be referring to something else. – mowshowitz Jan 16 '18 at 17:27
  • Yes, they are shown just above Global Options in the Tools menu. I always use projects so I've always had that available; if you don't use one, then it will be grayed out. However, I've been doing a bit of experimentation, and can't see how to avoid the behaviour you're seeing. Maybe this should be reported to RStudio as a bug report. – user2554330 Jan 16 '18 at 19:45
  • Okay, got it--at least I'm not alone. I appreciate the help. – mowshowitz Jan 16 '18 at 20:21

1 Answers1

5

This was driving me nuts too. Here's what I found (works in Rstudio Version 1.1.383 on Windows).

  • Check "Insert spaces for tab" (You've done this)
  • Set "Tab width" to 1
  • Restart Rstudio

Do this in your Global options. If you are using a project, do it in your Project Options as well (as pointed out by mowshowitz).

To see what is going on, select Global Options > Code > Display > Show whitespace characters. If you have "Insert spaces for tab" checked, it appears to truly insert spaces, but it forces your cursor to treat one tab-width's worth of spaces as a single character in the editor. By setting Tab width to 1, you can get around this limitation.

beandip
  • 186
  • 5