Open matsburg opened 5 years ago
I've worked on this a bit more now, the behaviour is only triggered for data.table
objects and so there's no need for the ncm_r_dt
option, which is removed. I've also added support for completion when using data.table
s with the magrittr
pipe %>%
, like this:
DT %>%
.[i, j, by]
Note that you can also do this with ordinary data.frame
s, i.e.
DF %>%
.[, "column_name"]
and completion works as expected in this case too. Coincidentally, this pipe completion behaviour isn't supported by RStudio :)
When adding this pipe behaviour I noticed that the regex used for detecting if completion is happening inside the brackets of a df doesn't allow for the name of the df to contain dots (since \w
includes '_' but not '.') Hence this PR also fixes this bug. But I'd be happy to split out this fix into a separate PR if it would be more appropriate.
This is where I've got to so far with the data.table completion behaviour as discussed in #18. There are two significant changes:
The regular expression for checking if the completion is happening inside the brackets of a data.frame (or data.table) is changed, so that completions are offered before the first comma is typed. This behaviour can be switched on and off with the
ncm_r_dt
setting, which is also added. I think it would be best to change this so that the class of the object is automatically detected, and this behaviour only happens when the object is a data.table. I think this should be possible - will work on it next.The other objective was to get function names as completions after the first comma is typed in a data.table command. The only way I've found to do this is to set
refresh = 1
in the call tocomplete()
, so that completions are refreshed as the user types. This is somewhat unsatisfactory since it isn't toggled by thencm_r_dt
setting (though could be I think), and presumably goes against the reason why you originally chose not to enable refreshing. Maybe it negatively impacts performance? I've not noticed a slowdown yet, but have only been working with small files. Let me know if you can think of a better solution to this problem.I've also added some test cases to demonstrate the behaviour I'm trying to get (which should currently all pass).