An open API service indexing awesome lists of open source software.

https://github.com/matt-dray/choosethis

:computer_mouse::crossed_swords: R package: off-label concepts for executing R code from links in the console, using {cli}
https://github.com/matt-dray/choosethis

cli r-package r-stats

Last synced: over 1 year ago
JSON representation

:computer_mouse::crossed_swords: R package: off-label concepts for executing R code from links in the console, using {cli}

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#",
fig.path = "man/figures/",
out.width = "100%",
eval = FALSE
)
```

# {choosethis}

[![Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept.](https://www.repostatus.org/badges/latest/concept.svg)](https://www.repostatus.org/#concept)
[![Blog post](https://img.shields.io/badge/rostrum.blog-post-008900?labelColor=000000&logo=data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhEAAQAPEAAAAAABWCBAAAAAAAACH5BAlkAAIAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAAC55QkISIiEoQQQgghRBBCiCAIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAAh%2BQQJZAACACwAAAAAEAAQAAAC55QkIiESIoQQQgghhAhCBCEIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAA7)](https://www.rostrum.blog/posts/2023-09-17-chosethis/)

Demonstrations of using [{cli}](https://cran.r-project.org/package=cli) to present clickable links to the user in their console. Read more in [the accompanying blogpost](https://www.rostrum.blog/posts/2023-09-17-chosethis/).

## Demos

You can install {choosethis} from GitHub.

```{r install}
if (!require(remotes)) install.packages("remotes")
install_github("matt-dray/choosethis")
library(choosethis)
```

### 1. Text adventure

To start a new game:

```{r begin}
begin()
```
```
You reach a fork in the road.
* Go left
* Go right
```

If your console supports links (e.g. RStudio), then the words 'left' and 'right' in the printout will be clickable (not shown above). Click one and you'll be taken to the next choice. If unsupported, you'll be shown functions to copy-paste yourself.

### 2. Summarise a data.frame

To begin:

```{r means}
ask_col_mean(ChickWeight)
```
```
What column would you like the mean of?
* weight
* Time
```

If your console supports links (e.g. RStudio), then the column names in the printout (`weight`, `Time`) will be clickable (not shown above). Click one and you'll be returned the mean value for that column.

## Theory

The [{cli} package](https://cran.r-project.org/package=cli) lets you present [clickable ANSI links](https://cli.r-lib.org/reference/links.html) to the user in supported terminals, such as RStudio.

`choosethis::begin()` uses [cli::ansi_has_hyperlink_support()](https://cli.r-lib.org/reference/style_hyperlink.html) to discover whether a user's terminal can support these links. If links aren't supported, then the underlying expression will be presented to the user instead of a clickable link.