From a8a38e530a9e2c755b0f9db058397d6ad923db1f Mon Sep 17 00:00:00 2001 From: dieghernan Date: Tue, 5 Sep 2023 06:12:55 +0000 Subject: [PATCH] Update docs --- .Rbuildignore | 3 + .github/dependabot.yml | 1 + .github/workflows/roscron-check-standard.yaml | 3 +- .github/workflows/rostemplate-docs.yaml | 6 +- .github/workflows/rostemplate-gh-pages.yaml | 7 +- .github/workflows/test-coverage.yaml | 3 +- .github/workflows/update-citation-cff.yaml | 2 +- .github/workflows/update-docs.yaml | 114 +++---- .github/workflows/wipe-cache.yaml | 21 +- .lintr | 3 + CITATION.cff | 3 +- DESCRIPTION | 4 +- R/ros_gh_actions_croncheck.R | 151 +++++---- _pkgdown.yml | 1 + codemeta.json | 8 +- inst/CITATION | 1 - inst/schemaorg.json | 38 +++ inst/yaml/roscron-check-standard.yaml | 3 +- inst/yaml/rostemplate-docs.yaml | 4 +- inst/yaml/rostemplate-gh-pages.yaml | 5 +- rostemplate.Rproj | 1 + vignettes/articles/highlight_test.Rmd | 320 +++++++++--------- 22 files changed, 371 insertions(+), 331 deletions(-) create mode 100644 .lintr create mode 100644 inst/schemaorg.json diff --git a/.Rbuildignore b/.Rbuildignore index 5a3816c..c371a74 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -25,3 +25,6 @@ ^pkgdown\.yaml$ ^pkgdown\.yml$ ^\.imgbotconfig$ +^\.lintr$ +^CODE_OF_CONDUCT\.md$ +^CONTRIBUTING\.md$ diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a1761a3..03b62d6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,3 +13,4 @@ updates: directory: "/" schedule: interval: "weekly" + diff --git a/.github/workflows/roscron-check-standard.yaml b/.github/workflows/roscron-check-standard.yaml index f1e52c3..62f4e49 100644 --- a/.github/workflows/roscron-check-standard.yaml +++ b/.github/workflows/roscron-check-standard.yaml @@ -31,7 +31,7 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -45,3 +45,4 @@ jobs: needs: check - uses: r-lib/actions/check-r-package@v2 + diff --git a/.github/workflows/rostemplate-docs.yaml b/.github/workflows/rostemplate-docs.yaml index 660ced1..6c5ccd9 100644 --- a/.github/workflows/rostemplate-docs.yaml +++ b/.github/workflows/rostemplate-docs.yaml @@ -9,11 +9,11 @@ name: rostemplate-docs jobs: rostemplate-docs: - runs-on: ubuntu-latest + runs-on: windows-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -47,4 +47,4 @@ jobs: git commit -m 'Build pkgdown' || echo "No changes to commit" git push origin || echo "No changes to commit" - + diff --git a/.github/workflows/rostemplate-gh-pages.yaml b/.github/workflows/rostemplate-gh-pages.yaml index 6b69717..1acf018 100644 --- a/.github/workflows/rostemplate-gh-pages.yaml +++ b/.github/workflows/rostemplate-gh-pages.yaml @@ -12,11 +12,11 @@ name: rostemplate-gh-pages jobs: rostemplate-gh-pages: - runs-on: ubuntu-latest + runs-on: windows-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -41,4 +41,5 @@ jobs: run: | git config --local user.name "github-actions[bot]" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' \ No newline at end of file + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' + diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 0c3b41c..f2a9ef2 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -15,7 +15,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 with: @@ -29,3 +29,4 @@ jobs: - name: Test coverage run: covr::codecov() shell: Rscript {0} + diff --git a/.github/workflows/update-citation-cff.yaml b/.github/workflows/update-citation-cff.yaml index 7afd874..6a9795c 100644 --- a/.github/workflows/update-citation-cff.yaml +++ b/.github/workflows/update-citation-cff.yaml @@ -22,7 +22,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 with: diff --git a/.github/workflows/update-docs.yaml b/.github/workflows/update-docs.yaml index de3354a..467ffd9 100644 --- a/.github/workflows/update-docs.yaml +++ b/.github/workflows/update-docs.yaml @@ -1,57 +1,57 @@ -on: - workflow_dispatch: - -name: update-docs - -jobs: - update-docs: - runs-on: windows-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - 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: | - local::. - any::rcmdcheck - any::pkgdown - any::cranlogs - any::tidyverse - any::jsonlite - any::lubridate - any::reactable - dieghernan/pkgdev - needs: website - - - name: Update docs - run: | - - pkgdev::update_docs() - - shell: Rscript {0} - - - name: Commit results - run: | - git config --local user.name "github-actions[bot]" - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -A - git commit -m 'Update docs with pkgdev' || echo "No changes to commit" - git push origin || echo "No changes to commit" - - - uses: r-lib/actions/check-r-package@v2 - - - name: Deploy package - run: | - git config --local user.name "github-actions[bot]" - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' - +on: + workflow_dispatch: + +name: update-docs + +jobs: + update-docs: + runs-on: windows-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + + - 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: | + local::. + any::rcmdcheck + any::pkgdown + any::cranlogs + any::tidyverse + any::jsonlite + any::lubridate + any::reactable + dieghernan/pkgdev + needs: website + + - name: Update docs + run: | + + pkgdev::update_docs() + + shell: Rscript {0} + + - name: Commit results + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m 'Update docs with pkgdev' || echo "No changes to commit" + git push origin || echo "No changes to commit" + + - uses: r-lib/actions/check-r-package@v2 + + - name: Deploy package + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' + diff --git a/.github/workflows/wipe-cache.yaml b/.github/workflows/wipe-cache.yaml index 976a157..cde45a1 100644 --- a/.github/workflows/wipe-cache.yaml +++ b/.github/workflows/wipe-cache.yaml @@ -1,10 +1,11 @@ -name: Clear GHA caches manually -on: - workflow_dispatch: - -jobs: - cache-clear: - runs-on: ubuntu-latest - - steps: - - uses: easimon/wipe-cache@main +name: Clear GHA caches manually +on: + workflow_dispatch: + +jobs: + cache-clear: + runs-on: ubuntu-latest + + steps: + - uses: easimon/wipe-cache@main + diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..d4708be --- /dev/null +++ b/.lintr @@ -0,0 +1,3 @@ +linters: linters_with_defaults() # see vignette("lintr") +encoding: "UTF-8" +exclusions: list("data-raw") diff --git a/CITATION.cff b/CITATION.cff index 2be624f..ace070d 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -8,7 +8,7 @@ message: 'To cite package "rostemplate" in publications use:' type: software license: MIT title: 'rostemplate: Plantilla ''pkgdown'' para los paquetes de ''rOpenSpain''' -version: 0.1.1.9000 +version: 0.1.1.9100 abstract: Plantilla privada para uso exclusivo de los paquetes de rOpenSpain. authors: - family-names: Hernangómez @@ -26,7 +26,6 @@ preferred-citation: orcid: https://orcid.org/0000-0001-8457-4658 affiliation: rOpenSpain year: '2023' - version: 0.1.1.9000 url: https://ropenspain.github.io/rostemplate/ abstract: Plantilla privada para uso exclusivo de los paquetes de rOpenSpain. repository-code: https://github.com/ropenspain/rostemplate diff --git a/DESCRIPTION b/DESCRIPTION index 7073ffc..faa45e6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rostemplate Title: Plantilla 'pkgdown' para los paquetes de 'rOpenSpain' -Version: 0.1.1.9000 +Version: 0.1.1.9100 Authors@R: person("Diego", "Hernangómez", , "diego.hernangomezherrero@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0001-8457-4658", affiliation = "rOpenSpain")) @@ -24,8 +24,8 @@ Suggests: testthat (>= 3.0.0) VignetteBuilder: knitr -Config/testthat/edition: 3 Config/Needs/website: ropenspain/rostemplate, ggplot2 +Config/testthat/edition: 3 Encoding: UTF-8 Language: es_ES Roxygen: list(markdown = TRUE) diff --git a/R/ros_gh_actions_croncheck.R b/R/ros_gh_actions_croncheck.R index db85106..a923c8c 100644 --- a/R/ros_gh_actions_croncheck.R +++ b/R/ros_gh_actions_croncheck.R @@ -1,75 +1,76 @@ -#' Crea una acción GitHub que comprueba tu paquete de manera regular -#' -#' @description -#' La acción GitHub creada ejecuta `R CMD check` para tu paquete. -#' La configuración por defecto ejecuta el check de manera mensual los dias 1 -#' de mes a las 08:30 AM. -#' -#' @details -#' Puedes aprender cómo configurar la acción cron en el siguiente link: -#' . -#' -#' La configuración por defecto `'30 08 1 * *'` ("A las 08:30 del -#' dia-del-mes 1."). -#' -#' Usa [crontab.guru](https://crontab.guru/#30_08_1_*_*) para crear tus propia -#' configuración cron. -#' -#' @source -#' -#' @export -#' -#' @inheritParams ros_actions_pkgdown_docs -#' -ros_actions_check_cron <- - function(pkg = ".", overwrite = TRUE) { - # Check destdir - - destdir <- file.path(pkg, ".github", "workflows") - checkdir <- dir.exists(destdir) - if (isFALSE(checkdir)) { - dir.create(destdir, recursive = TRUE) - } - - # Check .Rbuildignore - - Rbuildignore <- file.path(pkg, ".Rbuildignore") - if (!file.exists(Rbuildignore)) { - file.create(Rbuildignore) - } - - # Add lines to Rbuildignore - linesRbuild <- readLines(Rbuildignore) - newlinesRbuild <- - unique(c(linesRbuild, "^\\.github$", "^docs$", "^_pkgdown\\.yml$")) - newlinesRbuild <- newlinesRbuild[newlinesRbuild != ""] - writeLines(newlinesRbuild, Rbuildignore) - - # Check gitignore - - gitignore <- file.path(pkg, ".github", ".gitignore") - if (!file.exists(gitignore)) { - file.create(gitignore) - } - - # Add lines to gitignore - lines <- readLines(gitignore) - newlines <- - unique(c(lines, "*.html", "R-version", "depends.Rds")) - newlines <- newlines[newlines != ""] - writeLines(newlines, gitignore) - - # Get action file - filepath <- - system.file("yaml/roscron-check-standard.yaml", package = "rostemplate") - - # Copy - result <- file.copy(filepath, destdir, overwrite = overwrite) - if (result) { - message("Success!") - } else { - message("File not updated") - } - - return(invisible()) - } +#' Crea una acción GitHub que comprueba tu paquete de manera regular +#' +#' @description +#' La acción GitHub creada ejecuta `R CMD check` para tu paquete. +#' La configuración por defecto ejecuta el check de manera mensual los dias 1 +#' de mes a las 08:30 AM. +#' +#' @details +#' Puedes aprender cómo configurar la acción cron en el siguiente link: +#' . +#' +#' La configuración por defecto `'30 08 1 * *'` ("A las 08:30 del +#' dia-del-mes 1."). +#' +#' Usa [crontab.guru](https://crontab.guru/#30_08_1_*_*) para crear tus propia +#' configuración cron. +#' +#' @source +#' +#' +#' @export +#' +#' @inheritParams ros_actions_pkgdown_docs +#' +ros_actions_check_cron <- + function(pkg = ".", overwrite = TRUE) { + # Check destdir + + destdir <- file.path(pkg, ".github", "workflows") + checkdir <- dir.exists(destdir) + if (isFALSE(checkdir)) { + dir.create(destdir, recursive = TRUE) + } + + # Check .Rbuildignore + + Rbuildignore <- file.path(pkg, ".Rbuildignore") + if (!file.exists(Rbuildignore)) { + file.create(Rbuildignore) + } + + # Add lines to Rbuildignore + linesRbuild <- readLines(Rbuildignore) + newlinesRbuild <- + unique(c(linesRbuild, "^\\.github$", "^docs$", "^_pkgdown\\.yml$")) + newlinesRbuild <- newlinesRbuild[newlinesRbuild != ""] + writeLines(newlinesRbuild, Rbuildignore) + + # Check gitignore + + gitignore <- file.path(pkg, ".github", ".gitignore") + if (!file.exists(gitignore)) { + file.create(gitignore) + } + + # Add lines to gitignore + lines <- readLines(gitignore) + newlines <- + unique(c(lines, "*.html", "R-version", "depends.Rds")) + newlines <- newlines[newlines != ""] + writeLines(newlines, gitignore) + + # Get action file + filepath <- + system.file("yaml/roscron-check-standard.yaml", package = "rostemplate") + + # Copy + result <- file.copy(filepath, destdir, overwrite = overwrite) + if (result) { + message("Success!") + } else { + message("File not updated") + } + + return(invisible()) + } diff --git a/_pkgdown.yml b/_pkgdown.yml index 4af0094..b171ce1 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -23,3 +23,4 @@ lang: es authors: Diego Hernangómez: href: https://github.com/dieghernan/ + diff --git a/codemeta.json b/codemeta.json index 1843b13..aa95769 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,13 +8,13 @@ "codeRepository": "https://github.com/ropenspain/rostemplate", "issueTracker": "https://github.com/ropenspain/rostemplate/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.1.9000", + "version": "0.1.1.9100", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", "url": "https://r-project.org" }, - "runtimePlatform": "R version 4.3.0 (2023-04-21 ucrt)", + "runtimePlatform": "R version 4.3.1 (2023-06-16)", "author": [ { "@type": "Person", @@ -146,7 +146,7 @@ "SystemRequirements": null }, "isPartOf": "https://ropenspain.es/", - "fileSize": "245.759KB", + "fileSize": "245.087KB", "citation": [ { "@type": "SoftwareSourceCode", @@ -158,7 +158,7 @@ "familyName": "Hernangómez" } ], - "name": "{rostemplate}: Plantilla pkgdown para los paquetes de rOpenSpain", + "name": "{rostemplate}: Plantilla {pkgdown} para los paquetes de {rOpenSpain}", "url": "https://ropenspain.github.io/rostemplate/" } ], diff --git a/inst/CITATION b/inst/CITATION index eb84302..8dcc9ab 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -16,7 +16,6 @@ bibentry( title = paste("{rostemplate}:", title), author = c(person("Diego", "Hernangómez")), year = year, - version = meta$Version, url = unlist(strsplit(meta$URL, ","))[1], abstract = abs ) diff --git a/inst/schemaorg.json b/inst/schemaorg.json new file mode 100644 index 0000000..1315713 --- /dev/null +++ b/inst/schemaorg.json @@ -0,0 +1,38 @@ +{ + "@context": "https://schema.org", + "@graph": [ + { + "type": "SoftwareSourceCode", + "author": { + "id": "https://orcid.org/0000-0001-8457-4658" + }, + "codeRepository": "https://github.com/ropenspain/rostemplate", + "copyrightHolder": { + "id": "https://orcid.org/0000-0001-8457-4658", + "type": "Person", + "email": "diego.hernangomezherrero@gmail.com", + "familyName": "Hernangómez", + "givenName": "Diego" + }, + "description": "Plantilla privada para uso exclusivo de los paquetes de rOpenSpain.", + "license": "https://spdx.org/licenses/MIT", + "name": "rostemplate: Plantilla 'pkgdown' para los paquetes de 'rOpenSpain'", + "programmingLanguage": { + "type": "ComputerLanguage", + "name": "R", + "url": "https://r-project.org" + }, + "runtimePlatform": "R version 4.3.1 (2023-06-16)", + "version": "0.1.1.9100" + }, + { + "type": "SoftwareSourceCode", + "author": { + "type": "Person", + "familyName": "Hernangómez", + "givenName": "Diego" + }, + "name": "{rostemplate}: Plantilla {pkgdown} para los paquetes de {rOpenSpain}" + } + ] +} diff --git a/inst/yaml/roscron-check-standard.yaml b/inst/yaml/roscron-check-standard.yaml index f1e52c3..62f4e49 100644 --- a/inst/yaml/roscron-check-standard.yaml +++ b/inst/yaml/roscron-check-standard.yaml @@ -31,7 +31,7 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -45,3 +45,4 @@ jobs: needs: check - uses: r-lib/actions/check-r-package@v2 + diff --git a/inst/yaml/rostemplate-docs.yaml b/inst/yaml/rostemplate-docs.yaml index aa425e5..5742be5 100644 --- a/inst/yaml/rostemplate-docs.yaml +++ b/inst/yaml/rostemplate-docs.yaml @@ -13,7 +13,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -42,4 +42,4 @@ jobs: git commit -m 'Build pkgdown' || echo "No changes to commit" git push origin || echo "No changes to commit" - + diff --git a/inst/yaml/rostemplate-gh-pages.yaml b/inst/yaml/rostemplate-gh-pages.yaml index 95ccd16..350e58e 100644 --- a/inst/yaml/rostemplate-gh-pages.yaml +++ b/inst/yaml/rostemplate-gh-pages.yaml @@ -13,7 +13,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -33,4 +33,5 @@ jobs: run: | git config --local user.name "github-actions[bot]" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' \ No newline at end of file + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' + diff --git a/rostemplate.Rproj b/rostemplate.Rproj index f8c3af7..80bffa2 100644 --- a/rostemplate.Rproj +++ b/rostemplate.Rproj @@ -14,6 +14,7 @@ LaTeX: pdfLaTeX AutoAppendNewline: Yes StripTrailingWhitespace: Yes +LineEndingConversion: Posix BuildType: Package PackageUseDevtools: Yes diff --git a/vignettes/articles/highlight_test.Rmd b/vignettes/articles/highlight_test.Rmd index 1a0ee86..f4abf27 100644 --- a/vignettes/articles/highlight_test.Rmd +++ b/vignettes/articles/highlight_test.Rmd @@ -1,166 +1,154 @@ ---- -title: "Testing syntax highlighter" ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -Test how `pkgdown` highlights **R** code: - - -```{r eval=FALSE} -library("knitr") -library("rmarkdown") - - -library(sf) -library(jsonlite) -library(rnaturalearth) -library(dplyr) - - -df <- fromJSON("https://raw.githubusercontent.com/dieghernan/Country-Codes-and-International-Organizations/master/outputs/Countrycodesfull.json") -# Identify Commonwealth acronym -orgsdb <- read.csv("https://raw.githubusercontent.com/dieghernan/Country-Codes-and-International-Organizations/master/outputs/CountrycodesOrgs.csv") %>% - distinct(org_id, org_name) - -kable(orgsdb[grep("Common", orgsdb$org_name), ], format = "markdown") - - -ISO_memcol <- function(df, - orgtosearch) { - ind <- match(orgtosearch, unlist(df[1, "org_id"])) - or <- lapply(1:nrow(df), function(x) { - unlist(df[x, "org_member"])[ind] - }) - or <- data.frame(matrix(unlist(or)), stringsAsFactors = F) - names(or) <- orgtosearch - df2 <- as.data.frame(cbind(df, or, stringsAsFactors = F)) - return(df2) -} -df_org <- ISO_memcol(df, "C") - - -df_org %>% - count(C) %>% - kable(format = "markdown") - -df_org %>% - filter(!is.na(C)) %>% - select( - ISO_3166_3, - NAME.EN, - C - ) %>% - head() %>% - kable(format = "markdown") - - -testmap <- ne_countries(50, - "countries", - returnclass = "sf" -) %>% - select(ISO_3166_3 = adm0_a3) %>% - full_join(df_org) - -# We add also tiny countries -tiny <- ne_countries(50, - "tiny_countries", - returnclass = "sf" -) %>% - select(ISO_3166_3 = adm0_a3) %>% - full_join(df_org) - -# Identify dependencies -ISOCommon <- df_org %>% - filter(!is.na(C)) %>% - select( - ISO_3166_3.sov = ISO_3166_3, - C_sov = C - ) -tiny <- left_join(tiny, ISOCommon) -tiny$C <- coalesce(tiny$C, tiny$C_sov) - - -# Projecting the map -testmap_rob <- st_transform(testmap, "+proj=robin") -tiny_rob <- st_transform(tiny, "+proj=robin") - -# Bounding box -bbox <- st_linestring(rbind( - c(-180, 90), - c(180, 90), - c(180, -90), - c(-180, -90), - c(-180, 90) -)) %>% - st_segmentize(5) %>% - st_cast("POLYGON") %>% - st_sfc(crs = 4326) %>% - st_transform(crs = "+proj=robin") - -# Plotting -par(mar = c(0, 0, 0, 0), bg = NA) -plot(bbox, - col = "#FFFFFF", - border = "#AAAAAA", - lwd = 1.5 -) -plot( - st_geometry(testmap_rob), - col = "#B9B9B9", - border = "#FFFFFF", - lwd = 0.1, - add = T -) - -plot( - st_geometry(testmap_rob %>% - filter(!is.na(C))), - col = "#346733", - border = "#FFFFFF", - lwd = 0.1, - add = T -) - -# By last, add tiny countries -# All -plot( - st_geometry(tiny_rob), - col = "#000000", - bg = "#B9B9B9", - add = T, - pch = 21 -) -# Dependencies -plot( - st_geometry(tiny_rob %>% - filter(!is.na(C)) %>% - filter(!is.na(ISO_3166_3.sov))), - bg = "#C6DEBD", - col = "#000000", - pch = 21, - add = T -) -# Independent -plot( - st_geometry(tiny_rob %>% - filter(!is.na(C)) %>% - filter(is.na(ISO_3166_3.sov))), - bg = "#346733", - col = "#000000", - pch = 21, - add = T -) -plot(bbox, - col = NA, - border = "#AAAAAA", - lwd = 1.5, - add = T -) - -``` +--- +title: "Testing syntax highlighter" +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +Test how `pkgdown` highlights **R** code: + + +```{r eval=FALSE} +library("knitr") +library("rmarkdown") + + +library(sf) +library(jsonlite) +library(rnaturalearth) +library(dplyr) + + +df <- fromJSON("https://raw.githubusercontent.com/dieghernan/Country-Codes-and-International-Organizations/master/outputs/Countrycodesfull.json") +# Identify Commonwealth acronym +orgsdb <- read.csv("https://raw.githubusercontent.com/dieghernan/Country-Codes-and-International-Organizations/master/outputs/CountrycodesOrgs.csv") %>% + distinct(org_id, org_name) + +kable(orgsdb[grep("Common", orgsdb$org_name), ], format = "markdown") + + +ISO_memcol <- function(df, orgtosearch) { + ind <- match(orgtosearch, unlist(df[1, "org_id"])) + or <- lapply(seq_len(nrow(df)), function(x) { + unlist(df[x, "org_member"])[ind] + }) + or <- data.frame(matrix(unlist(or)), stringsAsFactors = FALSE) + names(or) <- orgtosearch + df2 <- as.data.frame(cbind(df, or, stringsAsFactors = FALSE)) + return(df2) +} +df_org <- ISO_memcol(df, "C") + + +df_org %>% + count(C) %>% + kable(format = "markdown") + +df_org %>% + filter(!is.na(C)) %>% + select( + ISO_3166_3, + NAME.EN, + C + ) %>% + head() %>% + kable(format = "markdown") + + +testmap <- ne_countries(50, + "countries", + returnclass = "sf" +) %>% + select(ISO_3166_3 = adm0_a3) %>% + full_join(df_org) + +# We add also tiny countries +tiny <- ne_countries(50, + "tiny_countries", + returnclass = "sf" +) %>% + select(ISO_3166_3 = adm0_a3) %>% + full_join(df_org) + +# Identify dependencies +ISOCommon <- df_org %>% + filter(!is.na(C)) %>% + select( + ISO_3166_3.sov = ISO_3166_3, + C_sov = C + ) +tiny <- left_join(tiny, ISOCommon) +tiny$C <- coalesce(tiny$C, tiny$C_sov) + + +# Projecting the map +testmap_rob <- st_transform(testmap, "+proj=robin") +tiny_rob <- st_transform(tiny, "+proj=robin") + +# Bounding box +bbox <- st_linestring(rbind( + c(-180, 90), + c(180, 90), + c(180, -90), + c(-180, -90), + c(-180, 90) +)) %>% + st_segmentize(5) %>% + st_cast("POLYGON") %>% + st_sfc(crs = 4326) %>% + st_transform(crs = "+proj=robin") + +# Plotting +par(mar = c(0, 0, 0, 0), bg = NA) +plot(bbox, + col = "#FFFFFF", + border = "#AAAAAA", + lwd = 1.5 +) +plot( + st_geometry(testmap_rob), + col = "#B9B9B9", + border = "#FFFFFF", + lwd = 0.1, + add = TRUE +) + +plot( + st_geometry( + testmap_rob %>% filter(!is.na(C)) + ), + col = "#346733", border = "#FFFFFF", lwd = 0.1, add = TRUE +) + +# By last, add tiny countries +# All +plot( + st_geometry(tiny_rob), + col = "#000000", + bg = "#B9B9B9", + add = TRUE, + pch = 21 +) +# Dependencies +plot( + st_geometry( + tiny_rob %>% filter(!is.na(C)) %>% filter(!is.na(ISO_3166_3.sov)) + ), + bg = "#C6DEBD", col = "#000000", pch = 21, add = TRUE +) +# Independent +plot( + st_geometry(tiny_rob %>% filter(!is.na(C)) %>% filter(is.na(ISO_3166_3.sov))), + bg = "#346733", col = "#000000", pch = 21, add = TRUE +) +plot(bbox, + col = NA, + border = "#AAAAAA", + lwd = 1.5, + add = TRUE +) +```