diff --git a/.Rbuildignore b/.Rbuildignore index 985228e..5075c69 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,6 @@ ^paintbrush\.Rproj$ ^\.Rproj\.user$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..ed7650c --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index 7c794aa..457525e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .httr-oauth .DS_Store .quarto +docs diff --git a/DESCRIPTION b/DESCRIPTION index 9b8482c..cf08c16 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ Imports: utils Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 -URL: https://github.com/klbarnes20/paintbrush +URL: https://github.com/klbarnes20/paintbrush, https://klbarnes20.github.io/paintbrush/ BugReports: https://github.com/klbarnes20/paintbrush/issues Suggests: testthat (>= 3.0.0) diff --git a/R/colors.R b/R/colors.R index 91ccd45..ecb11bd 100644 --- a/R/colors.R +++ b/R/colors.R @@ -73,7 +73,7 @@ carpentries_pal <- function(discrete = TRUE) { #' #' print(p_fill_discrete) #' -#' p_fill_continuous <- ggplot(data, aes(x, y, fill = category)) + +#' p_fill_continuous <- ggplot(data, aes(x, y, fill = y)) + #' geom_bar(stat = 'identity') + #' scale_fill_carpentries(discrete = FALSE) + #' theme_carpentries() @@ -88,19 +88,19 @@ scale_fill_carpentries <- ...) { palette <- match.arg(palette) if (discrete) { - discrete_scale("fill", - "carpentries", - carpentries_pal(discrete = TRUE), + discrete_scale(aesthetics = "fill", + scale_name = "carpentries", + palette = carpentries_pal(discrete = TRUE), ...) } else { - scale_color_gradientn( + scale_fill_gradientn( ..., - colors = carpentries_pal(discrete = FALSE), + colors = carpentries_colors, values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", - aesthetics = "color" + aesthetics = "fill" ) } } diff --git a/R/theme.R b/R/theme.R index d7caabd..ec97a26 100644 --- a/R/theme.R +++ b/R/theme.R @@ -14,15 +14,7 @@ #' #' p1 <- ggplot(mtcars2) + #' geom_point(aes(x = wt, y = mpg, colour = gear)) + -#' labs( -#' title = "Fuel economy declines as weight increases", -#' subtitle = "(1973-74)", -#' caption = "Data from the 1974 Motor Trend US magazine.", -#' tag = "Figure 1", -#' x = "Weight (1000 lbs)", -#' y = "Fuel economy (mpg)", -#' colour = "Gears" -#' ) +#' theme_carpentries() #' theme_carpentries <- function() { theme_bw(base_size = 12) %+replace% @@ -30,9 +22,8 @@ theme_carpentries <- function() { plot.title = element_text(size = 14, face = "bold", hjust = 0.5, margin = margin(0, 0, 15, 0)), - axis.text = element_text(size = 9), - axis.text.x = element_text(angle = 0, vjust = 0.5), - axis.text.y = element_text(size = 9), + axis.text.x = element_blank(), + axis.ticks = element_blank(), axis.title = element_text(face = "bold", vjust = 0.5), strip.text = element_text(face = "bold"), strip.background = element_blank(), diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..13c6a52 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: https://klbarnes20.github.io/paintbrush/ +template: + bootstrap: 5 + diff --git a/tests/testthat/test-colors.R b/tests/testthat/test-colors.R index be54855..0eb71ae 100644 --- a/tests/testthat/test-colors.R +++ b/tests/testthat/test-colors.R @@ -11,9 +11,11 @@ test_that("discrete color palettes return expected colors", { # I expect the dp to return a vector of the first three # colors of carpentries_colors expect_equal(dp(3), unname(carpentries_colors[1:3])) - expect_equal(dp(14), unname(carpentries_colors[1:14])) - expect_warning(dp(15)) - expect_warning(dp(100)) + expect_equal(dp(14), unname(carpentries_colors)) + expect_warning(x15 <- dp(15), "have supplied 15") + expect_equal(x15, unname(c(carpentries_colors, NA))) + expect_warning(x100 <- dp(100), "have supplied 100") + expect_equal(x100, unname(c(carpentries_colors, rep(NA, 86)))) }) test_that("continuous color palettes return expected colors", {