learnr
我尝试使用包制作一种学习工具。我们有一个问题,其中一个是正确的答案:
我不想每次都手动输入错误的答案,而是想从数据框中随机获取错误的答案:
df1 <- tibble(letters = LETTERS, Number = 1:26)
如何从Number
答案 1、2 和 4 的列中随机获取单元格值。正确答案是答案 Nr.3。
在第一步中,我尝试使用deparse(substitute(df1[1,2]))
代替1
,但失败了。
---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---
```{r setup, include=FALSE}
library(learnr)
library(tidyverse)
knitr::opts_chunk$set(echo = FALSE)
df1 <- tibble(letters = LETTERS, Number = 1:26)
```
Question 1:
```{r quiz}
# This works not
quiz(
question("Which number has E?",
answer(deparse(substitute(df1[1,2]))),
answer(deparse(substitute(df1[4,2]))),
answer(deparse(substitute(df1[5,2])), correct = TRUE),
answer(deparse(substitute(df1[8,2])))
),
# This one works
question("Which number has E?",
answer("1"),
answer("4"),
answer("5", correct = TRUE),
answer("8")
)
)
```