Skip to content

Instantly share code, notes, and snippets.

@schochastics
Created October 5, 2023 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schochastics/7210beb802f57f4c55dd68950a9b0e55 to your computer and use it in GitHub Desktop.
Save schochastics/7210beb802f57f4c55dd68950a9b0e55 to your computer and use it in GitHub Desktop.
---
title: "Untitled"
format: html
---
```{r}
#| label: prepare
#| echo: true
url2raw <- function(url) {
raw_url <- sub("https://github.com", "https://raw.githubusercontent.com", url)
raw_url <- sub("blob/", "", raw_url)
sub("#.*$", "", raw_url)
}
parse_selection <- function(url) {
lines <- adaR::ada_get_hash(url)
lines <- gsub("#|L", "", lines)
lines <- gsub("-", ":", lines)
lines <- eval(parse(text = lines))
code <- readLines(url2raw(url))
cat("````r", code[lines], "````", sep = "\n")
# code[lines]
}
```
Do this
```r
#| echo: false
#| output: asis
url <- "https://github.com/schochastics/adaR/blob/ba3392c3772619c2650209d5c01397de54f70b79/R/has.R#L43-L47"
parse_selection(url)
```
to get this
```{r}
#| echo: false
#| output: asis
url <- "https://github.com/schochastics/adaR/blob/ba3392c3772619c2650209d5c01397de54f70b79/R/has.R#L43-L47"
parse_selection(url)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment