0

Given the following list, do I need to choose between cleaner code or autocompletion or can I have both? I'm using the newest version of RStudio on MacOS 10.10.5.

> l <- list()
> l$`__a` <- data.frame(`__ID` = stringi::stri_rand_strings(10, 1), col = stringi::stri_rand_strings(10, 1), check.names = F )
> l$`__b` <- data.frame(`__ID` = stringi::stri_rand_strings(10, 1), col = stringi::stri_rand_strings(10, 1), check.names = F )
> l$`__c` <- data.frame(`__ID` = stringi::stri_rand_strings(10, 1), col = stringi::stri_rand_strings(10, 1), check.names = F )

Autocomplete, but with backtick symbols (less clean and more difficult to programmatically manipulate):

> l$`__a`
   __ID col
1     i   u
2     4   V
3     b   Y
4     j   B
5     k   d
6     Z   Q
7     T   H
8     f   A
9     j   Y
10    k   P

With the [ operator and strings (more clean and easier to programmatically manipulate, but without autocomplete):

> l[["__a"]]
   __ID col
1     i   u
2     4   V
3     b   Y
4     j   B
5     k   d
6     Z   Q
7     T   H
8     f   A
9     j   Y
10    k   P

Or is there a third possibility, for example writing all of the code first with backtick symbols and then finding a way to automatically replace them with [[ and ]]?

Bobby
  • 1,585
  • 3
  • 19
  • 42
  • 1
    auto-complete also works with `[[` extraction. Enter: `l` (the object name), then `[[` and hit the tab button – talat Oct 19 '16 at 09:19

1 Answers1

1

Fortunately, it's possible to have both autocomplete and nicely formatted code. In RStudio, autocomplete works for both $ and [[ but it functions slightly differently.

For indexing with $, the autocomplete list is triggered immediately after typing $.

However, for [[, it's necessary to press tab before the autocomplete list is shown. And this works multiple levels deep just as it does with $.

The comment above from @docendo discimus was helpful in finding this answer.

Bobby
  • 1,585
  • 3
  • 19
  • 42