Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rostemplate #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
^\.travis\.yml$
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^docs$
^_pkgdown\.yml$
3 changes: 3 additions & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.html
R-version
depends.Rds
89 changes: 89 additions & 0 deletions .github/workflows/roscron-check-standard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '00 08 1 * *'



name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Restore R package cache
uses: actions/[email protected]
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
50 changes: 50 additions & 0 deletions .github/workflows/rostemplate-gh-pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
push:
branches:
- main
- master

name: rostemplate-gh-pages

jobs:
rostemplate-gh-pages:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
install.packages('devtools')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
uses: actions/[email protected]
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_github("ropenspain/rostemplate", dependencies = TRUE, force = TRUE)

shell: Rscript {0}

- name: Install package
run: R CMD INSTALL .

- name: Deploy package
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, clean = TRUE, run_dont_run = TRUE)'
47 changes: 47 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

name: test-coverage

jobs:
test-coverage:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
uses: actions/[email protected]
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
shell: Rscript {0}

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
41 changes: 28 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
Package: caRtociudad
Type: Package
Package: caRtociudad
Title: Interface to Cartociudad API
Version: 0.6.2
Date: 2018-05-13
Encoding: UTF-8
Authors@R: c(person("Carlos J.", "Gil Bellosta", email="[email protected]", role=c('cre', 'aut')),
person("Luz", "Frías", email = "[email protected]", role = "aut"))
Description: Access to Cartociudad cartography API, which provides mapping and other related services for Spain.
Imports: httr, jsonlite, xml2, plyr, geosphere, sp
Depends: R (>= 3.0.0)
Suggests: ggmap, testthat
URL: https://github.com/rOpenSpain/caRtociudad
Authors@R:
c(person(given = "Carlos J.",
family = "Gil Bellosta",
role = c("cre", "aut"),
email = "[email protected]"),
person(given = "Luz",
family = "Frías",
role = "aut",
email = "[email protected]"))
Description: Access to Cartociudad cartography API, which provides mapping
and other related services for Spain.
License: GPL-3
LazyLoad: yes
LazyData: yes
RoxygenNote: 6.0.1
URL: https://github.com/rOpenSpain/caRtociudad
Depends:
R (>= 3.0.0)
Imports:
geosphere,
httr,
jsonlite,
plyr,
sp,
xml2
Suggests:
ggmap,
testthat (>= 3.0.0)
ByteCompile: yes
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.1.1
8 changes: 8 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
template:
package: rostemplate

authors:
Carlos J. Gil Bellosta:
href: https://www.datanalytics.com/
Luz Frías:
href: https://github.com/koldLight
54 changes: 26 additions & 28 deletions tests/testthat/test-caRtociudad.R
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
context("requests")

test_that("cartociudad_geocode returns the location of a full address", {
result <- cartociudad_geocode("plaza de cascorro 11, 28005 madrid")

expect_that(nrow(result) > 0, is_true())
expect_true(nrow(result) > 0)
})

test_that("get_cartociudad_map returns a map for a valid location", {
map <- cartociudad_get_map(c(40.41137, -3.707168), 1)

expect_that(map, is_a("raster"))
expect_that(map, is_a("ggmap"))
expect_s3_class(map, "raster")
expect_s3_class(map, "ggmap")
})

test_that("get_cartociudad_location_info returns info for a valid location", {
result <- cartociudad_get_location_info(40.473219, -3.7227241)

expect_that(!is.null(result$seccion), is_true())
expect_that(!is.null(result$distrito), is_true())
expect_that(!is.null(result$provincia), is_true())
expect_that(!is.null(result$municipio), is_true())
expect_that(!is.null(result$ref.catastral), is_true())
expect_that(!is.null(result$url.ref.catastral), is_true())
expect_that(!is.null(result$tipo), is_true())
expect_that(!is.null(result$tipo.via), is_true())
expect_that(!is.null(result$nombre.via), is_true())
expect_that(!is.null(result$num.via), is_true())
expect_that(!is.null(result$num.via.id), is_true())
expect_that(!is.null(result$cod.postal), is_true())
expect_true(!is.null(result$seccion))
expect_true(!is.null(result$distrito))
expect_true(!is.null(result$provincia))
expect_true(!is.null(result$municipio))
expect_true(!is.null(result$ref.catastral))
expect_true(!is.null(result$url.ref.catastral))
expect_true(!is.null(result$tipo))
expect_true(!is.null(result$tipo.via))
expect_true(!is.null(result$nombre.via))
expect_true(!is.null(result$num.via))
expect_true(!is.null(result$num.via.id))
expect_true(!is.null(result$cod.postal))
})

test_that("cartociudad_reverse_geocode returns an address for a valid location", {
result <- cartociudad_reverse_geocode(40.473219, -3.7227241)

expect_that(!is.null(result$tipo), is_true())
expect_that(!is.null(result$tipo.via), is_true())
expect_that(!is.null(result$nombre.via), is_true())
expect_that(!is.null(result$num.via), is_true())
expect_that(!is.null(result$num.via.id), is_true())
expect_that(!is.null(result$municipio), is_true())
expect_that(!is.null(result$provincia), is_true())
expect_that(!is.null(result$cod.postal), is_true())
expect_true(!is.null(result$tipo))
expect_true(!is.null(result$tipo.via))
expect_true(!is.null(result$nombre.via))
expect_true(!is.null(result$num.via))
expect_true(!is.null(result$num.via.id))
expect_true(!is.null(result$municipio))
expect_true(!is.null(result$provincia))
expect_true(!is.null(result$cod.postal))
})

test_that("get_cartociudad_user_agent returns the package name and github repo url", {
Expand All @@ -49,12 +47,12 @@ test_that("get_cartociudad_user_agent returns the package name and github repo u
httr::stop_for_status(result)

user.agent <- httr::content(result)$"user-agent"
expect_that(length(grep("caRtociudad/[0-9.]+", user.agent)) == 1, is_true())
expect_that(length(grep("github.com/rOpenSpain/caRtociudad", user.agent)) == 1, is_true())
expect_true(length(grep("caRtociudad/[0-9.]+", user.agent)) == 1)
expect_true(length(grep("github.com/rOpenSpain/caRtociudad", user.agent)) == 1)
})

test_that("cartociudad_get_area with valid parameters returns a polygon", {
result <- cartociudad_get_area(40.3930144, -3.6596683, 500)

expect_that(nrow(result) > 2, is_true())
expect_true(nrow(result) > 2)
})