How to include code snippets in an R package

There are several code snippets that are invaluable to my workflow and play nicely with functions in my custom R package. Can I include these code snippets in my R package so that they are added to users' code snippets (with permissions of course) when they install my package?

Rmd snippet example

snippet sql
	```{sql, connection = conn, output.var = "${1:df}"}
	${2}
	```

its definitely possible because for example, I use the shinyapp snippet very often !
image
Afraid, I have to leave the 'how' to someone else.

Writing this function did the trick:

add_markdown_snippets <- function(my_file = '~/.R/snippets/markdown.snippets', append = TRUE){

my_text <- "

snippet sql
{sql, connection = conn, output.var = '${1:df}'} ${2}
"

cat(my_text, file = my_file, ...)

}

Now a user can execute this function after loading the package to update their snippets.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.