Search code examples
rclassrstudior-s4

Show elements, slots for S4 classes when you press Tab in constructor call


Just for the cake of convenience how to make R to show class's fields when you press Tab in constructor call? Let me show you what I mean - there is a class:

cEvent = setClass(
  "Event",

  representation(
    time = "POSIXct"
    )
)

then when you create an instance

earthquake = cEvent(

and you press Tab to show you what the input fields can be it just shows ... = where I would like to have time =

The reason is some of my classes have quite a number of fields and I dont want to look them up how exactly they spell every time I create an instance. Tiny thing, but a bit annoying.


Solution

  • Thanks for the feature request! We've generally seen code like this more often in the wild:

    setClass("Class", c(...))
    Class <- function(x, y, z) { new("Class", x, y, z) }
    

    That is, package authors generally create their own 'constructors' for S4 objects, and then autocompletion from RStudio (or other R environments) generally functions as expected.

    None the less, I've added this on the internal RStudio issue tracker and we'll see what we can do!