init commit
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
list: user.code_common_function
|
||||
code.language: r
|
||||
-
|
||||
|
||||
# base R
|
||||
as character: "as.character"
|
||||
as data frame: "as.data.frame"
|
||||
as date: "as.Date"
|
||||
as double: "as.double"
|
||||
as factor: "as.factor"
|
||||
as integer: "as.integer"
|
||||
as numeric: "as.numeric"
|
||||
base read RDS: "readRDS"
|
||||
base save RDS: "saveRDS"
|
||||
cable: "kable"
|
||||
correlation: "cor"
|
||||
count: "count"
|
||||
covariance: "cov"
|
||||
describe: "describe"
|
||||
eigen: "eigen"
|
||||
ex table: "xtable"
|
||||
get working directory: "getwd"
|
||||
head: "head"
|
||||
if else: "ifelse"
|
||||
install packages: "install.packages"
|
||||
is NA: "is.na"
|
||||
is not NA: "!is.na"
|
||||
length: "length"
|
||||
library: "library"
|
||||
list files: "list.files"
|
||||
list: "list"
|
||||
lm: "lm"
|
||||
log: "log"
|
||||
make directory: "dir.create"
|
||||
margins: "margins"
|
||||
max: "max"
|
||||
mean: "mean"
|
||||
min: "min"
|
||||
names: "names"
|
||||
paste: "paste0"
|
||||
print: "print"
|
||||
reorder: "reorder"
|
||||
repeat: "rep"
|
||||
scale: "scale"
|
||||
sequence along: "seq_along"
|
||||
sequence length: "seq_len"
|
||||
sequence: "seq"
|
||||
set working directory: "setwd"
|
||||
sort: "sort"
|
||||
subset: "subset"
|
||||
sum: "sum"
|
||||
summary: "summary"
|
||||
tail: "tail"
|
||||
tidy: "tidy"
|
||||
trim white space: "trimws"
|
||||
type: "typeof"
|
||||
unique: "unique"
|
||||
vector: "c"
|
||||
vee table: "vtable"
|
||||
view: "View"
|
||||
# dplyr
|
||||
anti join: "anti_join"
|
||||
arrange: "arrange"
|
||||
as tibble: "as_tibble"
|
||||
bind rows: "bind_rows"
|
||||
case when: "case_when"
|
||||
distinct: "distinct"
|
||||
everything: "everything"
|
||||
filter: "filter"
|
||||
full join: "full_join"
|
||||
glimpse: "glimpse"
|
||||
group by: "group_by"
|
||||
inner join: "inner_join"
|
||||
left join: "left_join"
|
||||
mutate: "mutate"
|
||||
pull: "pull"
|
||||
rename all: "rename_all"
|
||||
rename: "rename"
|
||||
right join: "right_join"
|
||||
select all: "select_all"
|
||||
select: "select"
|
||||
semi join: "semi_join"
|
||||
starts with: "starts_with"
|
||||
summarise: "summarise"
|
||||
tibble: "tibble"
|
||||
ungroup: "ungroup"
|
||||
# ggplot2
|
||||
coord cartesian: "coor_cartesian"
|
||||
element text: "element_text"
|
||||
element blank: "element_blank"
|
||||
facet grid: "facet_grid"
|
||||
facet wrap: "facet_wrap"
|
||||
geom A B line: "geom_abline"
|
||||
geom area: "geom_area"
|
||||
geom bar: "geom_bar"
|
||||
geom boxplot: "geom_boxplot"
|
||||
geom histogram: "geom_histogram"
|
||||
geom horizontal line: "geom_hline"
|
||||
geom line: "geom_line"
|
||||
geom point: "geom_point"
|
||||
geom pointrange: "geom_pointrange"
|
||||
geom polygon: "geom_polygon"
|
||||
geom ribbon: "geom_ribbon"
|
||||
geom segment: "geom_segment"
|
||||
geom smooth: "geom_smooth"
|
||||
geom vertical line: "geom_vline"
|
||||
geom violin: "geom_violin"
|
||||
labs: "labs"
|
||||
scale colour manual: "scale_colour_manual"
|
||||
scale fill manual: "scale_fill_manual"
|
||||
scale fill viridis: "scale_fill_viridis_c"
|
||||
scale colour viridis: "scale_colour_viridis_c"
|
||||
theme set: "theme_set"
|
||||
# purrr
|
||||
map character: "map_chr"
|
||||
map data frame: "map_dfr"
|
||||
map double: "map_dbl"
|
||||
map: "map"
|
||||
P map: "pmap"
|
||||
# stringr
|
||||
string contains: "str_detect"
|
||||
string detect: "str_detect"
|
||||
string replace all: "str_replace_all"
|
||||
string replace: "str_replace"
|
||||
# tidyr
|
||||
drop NA: "drop_na"
|
||||
gather: "gather"
|
||||
nest: "nest"
|
||||
pivot longer: "pivot_longer"
|
||||
pivot wider: "pivot_wider"
|
||||
spread: "spread"
|
||||
un nest: "unnest"
|
||||
# readr readxl and other non-base R reading/writing
|
||||
read E views: "readEViews"
|
||||
read CSV: "read_csv"
|
||||
read RDS: "read_rds"
|
||||
read excel: "read_xlsx"
|
||||
write CSV: "write_csv"
|
||||
write RDS: "write_rds"
|
||||
# Shiny
|
||||
shine ui: "shinyUI"
|
||||
title panel: "titlePanel"
|
||||
main panel: "mainPanel"
|
||||
tab panel: "tabPanel"
|
||||
navigation list panel: "navlistPanel"
|
||||
conditional panel: "conditionalPanel"
|
||||
input panel: "inputPanel"
|
||||
ui output: "uiOutput"
|
||||
text output: "textOutput"
|
||||
table output: "tableOutput"
|
||||
data table output: "dataTableOutput"
|
||||
select size input: "selectizeInput"
|
||||
action button: "actionButton"
|
||||
download button: "downloadButton"
|
||||
render ui: "renderUI"
|
||||
observe event: "observeEvent"
|
||||
# Base
|
||||
@@ -0,0 +1,151 @@
|
||||
from talon import Context, actions, settings
|
||||
|
||||
from ..tags.operators import Operators
|
||||
|
||||
ctx = Context()
|
||||
|
||||
ctx.matches = r"""
|
||||
code.language: r
|
||||
"""
|
||||
|
||||
|
||||
ctx.lists["user.code_libraries"] = {
|
||||
"bayes plot": "bayesplot",
|
||||
"BRMS": "brms",
|
||||
"cable": "kable",
|
||||
"car": "car",
|
||||
"D plier": "dplyr",
|
||||
"dev tools": "devtools",
|
||||
"future": "future",
|
||||
"furr": "furrr",
|
||||
"gap minder": "gapminder",
|
||||
"gee animate": "gganimate",
|
||||
"gee highlight": "gghighlight",
|
||||
"gee map": "ggmap",
|
||||
"gee repel": "ggrepel",
|
||||
"grid extra": "gridExtra",
|
||||
"gee gee plot": "ggplot2",
|
||||
"GLMM TMB": "glmmTMB",
|
||||
"here": "here",
|
||||
"knitter": "knitr",
|
||||
"LME four": "lme4",
|
||||
"LM test": "lmtest",
|
||||
"lubridate": "lubridate",
|
||||
"margins": "margins",
|
||||
"inla": "INLA",
|
||||
"NLME": "nlme",
|
||||
"psych": "psych",
|
||||
"purr": "purrr",
|
||||
"R markdown": "rmarkdown",
|
||||
"R stan": "rstan",
|
||||
"R stan arm": "rstanarm",
|
||||
"R color brewer": "RColorBrewer",
|
||||
"read R": "readr",
|
||||
"stargazer": "stargazer",
|
||||
"tidy verse": "tidyverse",
|
||||
"tidier": "tidyr",
|
||||
"tidy bayes": "tidybayes",
|
||||
"TMB": "TMB",
|
||||
"vee table": "vtable",
|
||||
"viridis": "viridis",
|
||||
"viridis light": "viridisLite",
|
||||
"shiny alert": "shinyalert",
|
||||
}
|
||||
|
||||
ctx.lists["user.code_parameter_name"] = {
|
||||
"alpha": "alpha",
|
||||
"breaks": "breaks",
|
||||
"colour": "colour",
|
||||
"data": "data",
|
||||
"fill": "fill",
|
||||
"H just": "hjust",
|
||||
"keep": ".keep",
|
||||
"label": "label",
|
||||
"labels": "labels",
|
||||
"log": "log",
|
||||
"main": "main",
|
||||
"mapping": "mapping",
|
||||
"method": "method",
|
||||
"NA remove": "na.rm",
|
||||
"path": "path",
|
||||
"position": "position",
|
||||
"plex label": "xlab",
|
||||
"plex limit": "xlim",
|
||||
"scales": "scales",
|
||||
"size": "size",
|
||||
"show legend": "show.legend",
|
||||
"sort": "sort",
|
||||
"title": "title",
|
||||
"type": "type",
|
||||
"vee just": "vjust",
|
||||
"width": "width",
|
||||
"with ties": "with_ties",
|
||||
"why label": "ylab",
|
||||
"why limit": "ylim",
|
||||
"why max": "ymax",
|
||||
"why min": "ymin",
|
||||
}
|
||||
|
||||
operators = Operators(
|
||||
# code_operators_assignment
|
||||
ASSIGNMENT=" <- ",
|
||||
# code_operators_bitwise
|
||||
BITWISE_AND=" & ",
|
||||
# code_operators_math:
|
||||
MATH_SUBTRACT=" - ",
|
||||
MATH_ADD=" + ",
|
||||
MATH_MULTIPLY=" * ",
|
||||
MATH_EXPONENT=" ** ",
|
||||
MATH_DIVIDE=" / ",
|
||||
MATH_MODULO=" %% ",
|
||||
MATH_EQUAL=" == ",
|
||||
MATH_NOT_EQUAL=" != ",
|
||||
MATH_GREATER_THAN=" > ",
|
||||
MATH_GREATER_THAN_OR_EQUAL=" >= ",
|
||||
MATH_LESS_THAN=" < ",
|
||||
MATH_LESS_THAN_OR_EQUAL=" <= ",
|
||||
MATH_AND=" & ",
|
||||
MATH_OR=" | ",
|
||||
MATH_IN=" %in% ",
|
||||
)
|
||||
|
||||
|
||||
@ctx.action_class("user")
|
||||
class UserActions:
|
||||
def code_get_operators() -> Operators:
|
||||
return operators
|
||||
|
||||
def code_insert_null():
|
||||
actions.auto_insert("NULL")
|
||||
|
||||
def code_insert_true():
|
||||
actions.auto_insert("TRUE")
|
||||
|
||||
def code_insert_false():
|
||||
actions.auto_insert("FALSE")
|
||||
|
||||
def code_insert_function(text: str, selection: str):
|
||||
text += f"({selection or ''})"
|
||||
actions.user.paste(text)
|
||||
actions.edit.left()
|
||||
|
||||
def code_private_function(text: str):
|
||||
result = "{} <- function () {{\n\n}}".format(
|
||||
actions.user.formatted_text(
|
||||
text, settings.get("user.code_private_function_formatter")
|
||||
)
|
||||
)
|
||||
|
||||
actions.user.paste(result)
|
||||
actions.edit.up()
|
||||
actions.edit.up()
|
||||
actions.edit.line_end()
|
||||
actions.edit.left()
|
||||
actions.edit.left()
|
||||
actions.edit.left()
|
||||
|
||||
def code_insert_library(text: str, selection: str):
|
||||
actions.user.insert_snippet_by_name("importStatement", {"0": text + selection})
|
||||
|
||||
def code_insert_named_argument(parameter_name: str):
|
||||
actions.insert(f"{parameter_name} = ")
|
||||
@@ -0,0 +1,38 @@
|
||||
code.language: r
|
||||
-
|
||||
tag(): user.code_imperative
|
||||
|
||||
tag(): user.code_comment_line
|
||||
tag(): user.code_data_bool
|
||||
tag(): user.code_data_null
|
||||
tag(): user.code_functions
|
||||
tag(): user.code_functions_common
|
||||
tag(): user.code_libraries
|
||||
tag(): user.code_operators_assignment
|
||||
tag(): user.code_operators_bitwise
|
||||
tag(): user.code_operators_math
|
||||
|
||||
settings():
|
||||
user.code_private_function_formatter = "SNAKE_CASE"
|
||||
user.code_protected_function_formatter = "SNAKE_CASE"
|
||||
user.code_public_function_formatter = "SNAKE_CASE"
|
||||
user.code_private_variable_formatter = "SNAKE_CASE"
|
||||
user.code_protected_variable_formatter = "SNAKE_CASE"
|
||||
user.code_public_variable_formatter = "SNAKE_CASE"
|
||||
|
||||
library <user.code_libraries>:
|
||||
user.code_insert_library(code_libraries, "")
|
||||
key(end enter)
|
||||
|
||||
# R specific commands
|
||||
(chain | pipe that):
|
||||
key(end)
|
||||
" %>%"
|
||||
key(enter)
|
||||
state na: insert("NA")
|
||||
|
||||
# TODO: migrate to function tag
|
||||
^function define <user.text>$: user.code_private_function(text)
|
||||
|
||||
named arg {user.code_parameter_name}:
|
||||
user.code_insert_named_argument(code_parameter_name)
|
||||
Reference in New Issue
Block a user