简体   繁体   中英

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM