r - 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)?
解决方案
推荐阅读
- python - 如何有效地计算pytorch中两组不同大小的3D张量的距离矩阵?
- facebook - 如果客户没有被重定向到跟踪页面,如何跟踪 Facebook 广告的转化
- javascript - 检查电子邮件格式和小写英文字符
- visual-studio-code - 是否可以从 launch.json 解析 VSCode 命令行参数?
- javascript - 使用相对路径 php 导入 javascript 文件
- javascript - 如何使用 jquery 或 js 水平和垂直对齐图像?
- mysql - SQL 在一个查询中返回不同的值及其组合计数
- react-native-windows - 运行`npx react-native run-windows`时构建错误
- django - 注册后的 Django AllAuth 和 dj-rest-auth 自定义用户设置
- azure - 当集合具有分区键但分区键对于文档为空时,如何使用 SQL Rest API 从 cosmos db 获取文档?