Polars code completion
Description
Polars code completion
Usage
<polars>$code_completion_activate(
mode = c("auto", "rstudio", "native"),
verbose = TRUE
)
polars_code_completion_deactivate()
Arguments
mode
|
One of “auto” , “rstudio” , or
“native” . Automatic mode picks “rstudio” if
.Platform$GUI is “RStudio” .
“native” registers a custom line buffer completer with
utils:::rc.getOption(“custom.completer”) .
“rstudio” modifies RStudio code internal
.DollarNames and function args completion, as the IDE does
not behave well with
utils:::rc.getOption(“custom.completer”) .
|
verbose
|
Print message of what mode is started. |
Details
Polars code completion has one implementation for a native terminal via
utils:::rc.getOption(“custom.completer”)
and one for
Rstudio by intercepting Rstudio internal functions
.rs.getCompletionsFunction
&
.rs.getCompletionsDollar
in the loaded session environment
tools:rstudio
. Therefore, any error or slowness in the
completion is likely to come from r-polars implementation.
Either completers will evaluate the full line-buffer to decide what methods are available. Pressing tab will literally evaluate left-hand-side with any following side. This works swiftly for the polars lazy API, but it can take some time for the eager API depending on the size of the data and of the query.
Examples
library("polars")
if (interactive()) {
# activate completion
polars_code_completion_activate()
# method / property completion for chained expressions
# add a $ and press tab to see methods of LazyFrame
pl$LazyFrame(iris)
# Arg + column-name completion
# press tab inside group_by() to see args and/or column names.
pl$LazyFrame(iris)$group_by()
# deactivate like this or restart R session
polars_code_completion_deactivate()
}