Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v3
- name: install and update texlive
run: /usr/bin/sudo DEBIAN_FRONTEND=noninteractive apt update -y -qq
- run: /usr/bin/sudo DEBIAN_FRONTEND=noninteractive apt install texlive texlive-fonts-extra -y
- run: /usr/bin/sudo DEBIAN_FRONTEND=noninteractive apt install tidy texlive texlive-fonts-extra -y
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: animint2
Title: Animated Interactive Grammar of Graphics
Version: 2024.8.27
Version: 2024.8.29
URL: https://animint.github.io/animint2/
BugReports: https://github.com/animint/animint2/issues
Authors@R: c(
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Changes in version 2024.8.29 (PR#147)

- animint2pages initial commit README.md uses viz title.
- animint2pages gains owner argument, with default taken from `gh::gh_whoami` (same as before, always returns user, even when token has permissions on an org); this allows user to specify an org where the user/token has write permissions. This is used in a new test-compiler-ghpages.R, which now assumes `PAT_GITHUB` has Administration and Contents permissions for all repos in `animint-test` org, so our test code can delete the `animint2pages_test_repo`, create a new one, and then use animint2pages twice, to test the results of creation/update.

# Changes in version 2024.8.27 (PR#144)

- Remove selenium, combine renderer tests into single CI job.
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
#' Housing sales in TX.
#'
#' Information about the housing market in Texas provided by the TAMU
#' real estate center, \url{https://www.recenter.tamu.edu/}.
#' real estate center.
#'
#' @format A data frame with 8602 observations and 9 variables:
#' \describe{
Expand Down
3 changes: 0 additions & 3 deletions R/stat-unique.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#' Remove duplicates.
#'
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{animint2:::rd_aesthetics("stat", "unique")}
#'
#' @export
#' @inheritParams layer
#' @inheritParams geom_point
Expand Down
19 changes: 12 additions & 7 deletions R/z_pages.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @param plot.list A named list of ggplots and option lists.
#' @param github_repo The name of the GitHub repository to which the
#' files will be pushed.
#' @param owner The user/org under which the repo will be created, default comes from \code{gh::gh_whoami}.
#' @param commit_message A string specifying the commit message for
#' the pushed files.
#' @param private A logical flag indicating whether the GitHub
Expand Down Expand Up @@ -35,7 +36,7 @@
#' }
#'
#' @export
animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), ...) {
animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), ...) {
for(opt in required_opts){
if(!opt %in% names(plot.list)){
stop(sprintf("plot.list does not contain option named %s, which is required by animint2pages", opt))
Expand All @@ -61,8 +62,10 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from
stop("The github_repo argument should not contain '/'.")
}
# Check for existing repository
whoami <- suppressMessages(gh::gh_whoami())
owner <- whoami[["login"]]
if(is.null(owner)){
whoami <- suppressMessages(gh::gh_whoami())
owner <- whoami[["login"]]
}
viz_owner_repo <- paste0(owner, "/", github_repo)
local_clone <- tempfile()
if (!check_no_github_repo(owner, github_repo)) {
Expand All @@ -86,18 +89,20 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from
silent = TRUE
)
if (!has_commits) {
initial_commit(local_clone, repo, viz_url)
title <- plot.list[["title"]]
if(!is.character(title))title <- "New animint visualization"
initial_commit(local_clone, repo, viz_url, title)
}
# Handle gh-pages branch
manage_gh_pages(repo, to_post, local_clone, commit_message)
message(sprintf(
"Visualization will be available at %s\nDeployment via GitHub Pages may take a few minutes...", viz_url))
viz_owner_repo
list(owner_repo=viz_owner_repo, local_clone=local_clone, viz_url=viz_url, gh_pages_url=sprintf("https://github.com/%s/tree/gh-pages", viz_owner_repo))
}

initial_commit <- function(local_clone, repo, viz_url) {
initial_commit <- function(local_clone, repo, viz_url, title) {
readme_file_path <- file.path(local_clone, "README.md")
header <- "## New animint visualization\n"
header <- sprintf("## %s\n", title)
url_hyperlink <- sprintf("[%s](%s)\n", viz_url, viz_url)
full_content <- paste0(header, url_hyperlink)
writeLines(full_content, readme_file_path)
Expand Down
3 changes: 3 additions & 0 deletions man/animint2pages.Rd

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

5 changes: 0 additions & 5 deletions man/stat_unique.Rd

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

2 changes: 1 addition & 1 deletion man/txhousing.Rd

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

36 changes: 33 additions & 3 deletions tests/testthat/test-compiler-ghpages.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
acontext("GitHub Pages")

library(animint2)
viz <- animint(
title="one to ten",
source="https://github.com/animint/animint2/tree/master/tests/testthat/test-compiler-ghpages.R",
Expand All @@ -22,9 +23,38 @@ test_that("error for viz with no source", {
}, "plot.list does not contain option named source, which is required by animint2pages")
})

test_that("animint2pages() returns owner/repo string", {
viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo")
expect_is(viz_owner_repo, "character")
## The test below requires a github token with repo delete
## permission. Read
## https://github.com/animint/animint2/wiki/Testing#installation to
## see how to set that up on your local computer, or on github
## actions.
test_that("animint2pages() returns list of meta-data", {
## https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#delete-a-repository says The fine-grained token must have the following permission set: "Administration" repository permissions (write) gh api --method DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/OWNER/REPO
gh::gh("DELETE /repos/animint-test/animint2pages_test_repo")
## https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#create-an-organization-repository says The fine-grained token must have the following permission set: "Administration" repository permissions (write)
gh::gh("POST /orgs/animint-test/repos", name="animint2pages_test_repo")
## first run of animint2pages creates new data viz.
result_list <- animint2pages(viz, "animint2pages_test_repo", owner="animint-test")
result_list
expect_match(result_list$owner_repo, "animint2pages_test_repo")
expect_match(result_list$viz_url, "github.io/animint2pages_test_repo")
expect_match(result_list$gh_pages_url, "animint2pages_test_repo/tree/gh-pages")
README.md <- file.path(result_list$local_clone, "README.md")
README.lines <- readLines(README.md)
expected.line <- paste("##", viz$title)
expect_identical(README.lines[1], expected.line)
get_tsv <- function(L)Sys.glob(file.path(L$local_clone, "*tsv"))
tsv_files_created <- get_tsv(result_list)
expect_equal(length(tsv_files_created), 1)
## second run of animint2pages updates data viz.
viz.more <- viz
viz.more$five <- ggplot()+
geom_point(aes(
x, x),
data=data.frame(x=1:5))
update_list <- animint2pages(viz.more, "animint2pages_test_repo", owner="animint-test")
tsv_files_updated <- get_tsv(update_list)
expect_equal(length(tsv_files_updated), 2)
})

test_that("animint2pages raises an error if no GitHub token is present", {
Expand Down