首页 > 解决方案 > How can I inject symbols for autocompletion into R in a specific context?

问题描述

A couple of years ago, I hacked together a system that uses lazy evaluation to allow users to perform filter operations based on field names being returned by an API. This allows users to write R code that gets translated to API calls, but field names are treated as "variable names". For example:

files() %>% filter(~ file_id == "XYZ" & cases.case_id %in% c("a", "b"))

The file_id and cases.case_id are not R variables but are injected into the formula environment at evaluation. What I am looking for is a way to do autocomplete using these names as users type. The field names are known a priori given the context of files() and filter.

FYI, the package that implements this is the Bioconductor GenomicDataCommons package. Some of the relevant code is here.

Edit: To clarify and simplify even further, if I have a character vector of tokens, how can I have R do tab completion on those tokens in a given context (in this case, a formula context)?

标签: rautocomplete

解决方案


推荐阅读