Skip to content

Commit

Permalink
updated tdt docs
Browse files Browse the repository at this point in the history
  • Loading branch information
seankross committed Dec 9, 2021
1 parent f97622b commit 3deccc4
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 4 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
^LICENSE\.md$
^\.github$
^cran-comments\.md$
^CRAN-SUBMISSION$
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ Authors@R:
email = "[email protected]",
comment = c(ORCID = "0000-0001-5215-0316"))
Description: Visualize your 'Tidyverse' data analysis pipelines via the
'Tidy Data Tutor' web application.
'Tidy Data Tutor'(<https://tidydatatutor.com/>) web application.
License: MIT + file LICENSE
URL: https://github.com/seankross/tidydatatutor
BugReports: https://github.com/seankross/tidydatatutor/issues
Encoding: UTF-8
Imports:
Imports:
clipr,
knitr,
rstudioapi
RoxygenNote: 7.1.2
Suggests:
rmarkdown,
dplyr,
testthat (>= 3.0.0)
Config/testthat/edition: 3
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ export(go)
export(go_code)
export(go_paste)
export(go_selection)
export(tdt_chunk)
export(tdt_file)
export(tdt_link)
importFrom(clipr,clipr_available)
importFrom(clipr,read_clip)
importFrom(knitr,knit_code)
importFrom(rstudioapi,getSourceEditorContext)
importFrom(rstudioapi,verifyAvailable)
importFrom(utils,URLencode)
Expand Down
8 changes: 8 additions & 0 deletions R/go.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#'
#' @importFrom rstudioapi verifyAvailable getSourceEditorContext
#' @importFrom utils browseURL
#' @returns A string with an appropriately formatted URL to Tidy Data Tutor
#' (invisibly).
#' @export
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -33,6 +35,8 @@ go <- function(){
#'
#' @importFrom rstudioapi verifyAvailable getSourceEditorContext
#' @importFrom utils browseURL
#' @returns A string with an appropriately formatted URL to Tidy Data Tutor
#' (invisibly).
#' @export
#' @examples
#' \dontrun{
Expand All @@ -54,6 +58,8 @@ go_selection <- function(){
#'
#' @importFrom clipr clipr_available read_clip
#' @importFrom utils browseURL
#' @returns A string with an appropriately formatted URL to Tidy Data Tutor
#' (invisibly).
#' @export
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -85,6 +91,8 @@ go_paste <- function(){
#'
#' @param code A string of R code.
#' @importFrom utils browseURL
#' @returns A string with an appropriately formatted URL to Tidy Data Tutor
#' (invisibly).
#' @export
#' @examples
#' \dontrun{
Expand Down
58 changes: 58 additions & 0 deletions R/tdt_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,61 @@ tdt_url <- function(x){
sep = ""
)
}

#' Create a Link to Tidy Data Tutor
#'
#' @param code A string or vector of strings containing R code.
#' @returns A string with an appropriately formatted URL to Tidy Data Tutor.
#' @export
#' @examples
#' \dontrun{
#'
#' code <- "library(dplyr)
#' Formaldehyde %>% mutate(Sum = carb + optden)"
#'
#' tdt_link(code)
#'}
tdt_link <- function(code) {
tdt_url(code)
}

#' Create a Link to Tidy Data Tutor from an R Code Chunk
#'
#' @param chunk The name of an R code chunk in the current R Markdown document.
#' @importFrom knitr knit_code
#' @returns A string with an appropriately formatted URL to Tidy Data Tutor.
#' @export
#' @examples
#' \dontrun{
#'
#' <!--- In an R Markdown document: --->
#' ```{r mtcars-1}
#' library(dplyr)
#'
#' mtcars %>%
#' select(mpg, cyl, hp) %>%
#' group_by(cyl) %>%
#' summarise(mean(hp))
#' ```
#'
#' [See this pipeline in Tidy Data Tutor](`r tdt_chunk("mtcars-1")`)
#'}
tdt_chunk <- function(chunk) {
tdt_url(as.character(knit_code[["get"]](chunk)))
}

#' Create a Link to Tidy Data Tutor from an R Code File
#'
#' @param file The path to an R code file.
#' @returns A string with an appropriately formatted URL to Tidy Data Tutor.
#' @export
#' @examples
#' \dontrun{
#'
#' r_code_file <- system.file("test", "test-1.R", package = "tidydatatutor")
#' tdt_file(r_code_file)
#' }
tdt_file <- function(file) {
stopifnot(file.exists(file))
tdt_url(readLines(file))
}
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ Then open it in Tidy Data Tutor by running this in the console:
tidydatatutor::go_paste()
```

## R Markdown Support

Generate links to Tidy Data Tutor in R Markdown with named R code chunks:

---
output: md_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(message = FALSE)
library(tidydatatutor)
```

```{r mtcars-1}
library(dplyr)

mtcars %>%
select(mpg, cyl, hp) %>%
group_by(cyl) %>%
summarize(mean(hp))
```

[See this pipeline in Tidy Data Tutor](`r tdt_chunk("mtcars-1")`)

## RStudio Add-in

Access Tidy Data Tutor from the Addins drop down menu in RStudio:
Expand Down
6 changes: 6 additions & 0 deletions inst/test/test-1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library(dplyr)

mtcars %>%
select(mpg, cyl, hp) %>%
group_by(cyl) %>%
summarise(mean(hp))
19 changes: 19 additions & 0 deletions inst/test/test-1.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
output: md_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(message = FALSE)
library(tidydatatutor)
```

```{r mtcars-1}
library(dplyr)
mtcars %>%
select(mpg, cyl, hp) %>%
group_by(cyl) %>%
summarise(mean(hp))
```

[See this pipeline in Tidy Data Tutor](`r tdt_chunk("mtcars-1")`)
16 changes: 16 additions & 0 deletions inst/test/test-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library(dplyr)

mtcars %>%
select(mpg, cyl, hp) %>%
group_by(cyl) %>%
summarise(mean(hp))

## # A tibble: 3 × 2
## cyl `mean(hp)`
## <dbl> <dbl>
## 1 4 82.6
## 2 6 122.
## 3 8 209.

[See this pipeline in Tidy Data
Tutor](https://tidydatatutor.com/vis.html#code=library%28dplyr%29%0A%0Amtcars%20%25%3E%25%20%0A%20%20select%28mpg%2C%20cyl%2C%20hp%29%20%25%3E%25%20%0A%20%20group_by%28cyl%29%20%25%3E%25%20%0A%20%20summarise%28mean%28hp%29%29&d=2021-12-09&lang=r&v=v1)
4 changes: 4 additions & 0 deletions man/go.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/go_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/go_paste.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/go_selection.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions man/tdt_chunk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/tdt_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions man/tdt_link.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
test_that("tdt_url makes the correct url", {
test_that("tdt_link makes the correct url", {

input <- c("library(dplyr)", "library(palmerpenguins)", "", "penguins %>%",
" select(species, bill_length_mm) %>%", " group_by(species) %>%",
" arrange(desc(bill_length_mm), .by_group = TRUE) %>% ", " slice(1)"
)
correct <- paste0("https://tidydatatutor.com/vis.html#code=library%28dplyr%29%0Alibrary%28palmerpenguins%29%0A%0Apenguins%20%25%3E%25%0A%20%20select%28species%2C%20bill_length_mm%29%20%25%3E%25%0A%20%20group_by%28species%29%20%25%3E%25%0A%20%20arrange%28desc%28bill_length_mm%29%2C%20.by_group%20%3D%20TRUE%29%20%25%3E%25%20%0A%20%20slice%281%29&d=",
as.character(Sys.Date()), "&lang=r&v=v1")
expect_equal(correct, tdt_url(input))
expect_equal(correct, tdt_link(input))
})

0 comments on commit 3deccc4

Please sign in to comment.