Created
October 5, 2023 20:31
-
-
Save schochastics/7210beb802f57f4c55dd68950a9b0e55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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