diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..a3e5791 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,9 @@ +^renv$ +^renv\.lock$ +^eesyapi\.Rproj$ +^\.Rproj\.user$ +^LICENSE\.md$ +^_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/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..f121d3a --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,126 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at explore.statistics@education.gov.uk. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/inclusion). + +For answers to common questions about this code of conduct, see the FAQ at +. Translations are available at . + +[homepage]: https://www.contributor-covenant.org diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..0adc1c5 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,70 @@ +# Contributing to eesyapi + +Try and make use of the [usethis](https://usethis.r-lib.org/) package wherever possible. + +When you initially clone the package, the first thing you'll need to do is install [devtools](https://devtools.r-lib.org/): + +``` +install.packages("devtools") +``` + +Then to load in the package in its current form: + +``` +devtools::load_all() +``` + +## Adding a package/dependency + +`usethis::use_package()` + +Note that when adding a function from another package into one of the eesyapi functions you will need to explicitly state the package in the function call, e.g.: + +```package::function()``` + +Alternatively, if there's a lot of uses of a single function within one of our R scripts, you can call that function once at the top of the R script, e.g: + +``` +@' importFrom package function +``` + +For more information see the [roxygen2 documentation on declaring dependencies](https://roxygen2.r-lib.org/articles/namespace.html). + +## Creating a new function script + +`usethis::use_r(name = )` + +This will create a new script within the package [R/](R/) folder. + +## Creating a new function test script + +`usethis::use_test(name = )` + +This will create a new blank test script within the package [testthat/](testthat/) folder. + +## Updating the package version + +Once changes have been completed, reviewed and are ready for use in the wild, you +can increment the package version using: + +`usethis::use_version()` + +Once you've incremented the version number, it'll add a new heading to news.md. + +Add a summary under news.md and then accept it's offer to commit on your behalf. + +Once pushed and on the main branch, create a new release in GitHub itself. + +## Running tests + +You should run the following lines to test the package locally: +``` +# To check functionality +devtools::check() # Ctrl-Shft-E + +# For code styling +styler::style_pkg() +lintr::lint_package() +``` + +If you get a lot of lintr errors, particularly around things not being defined, make sure to load the package first using Ctrl-Shft-L or `devtools::load_all(".")`, then run again. There's a known issue with lintr not picking up on bindings until packages are loaded diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..e8c71b6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +## Describe the bug +A clear and concise description of what the bug is. + +## How to reproduce +Steps to reproduce the behaviour: +1. '...' +2. '....' +3. '....' +4. See error + +## Expected behaviour +A clear and concise description of what you expected to happen. + +## Screenshots +If applicable, add screenshots to help explain your problem. + +## Additional context +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..9946b93 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +## Is your feature request related to a problem? Please describe. +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...], or wouldn't it be nice if [...]. + +## Describe the solution you'd like +A clear and concise description of what you want to happen. + +## Describe alternatives you've considered +A clear and concise description of any alternative solutions or features you've considered. + +## Additional context +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..4431387 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ + + +# Brief overview of changes + +... + +## Why are these changes being made? + +... + +## Detailed description of changes + +... + +## Additional information for reviewers + +... + +## Issue ticket number/s and link + +... diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..74d8c97 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# 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] + +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: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/lintr.yml b/.github/workflows/lintr.yml new file mode 100644 index 0000000..8c8f5a9 --- /dev/null +++ b/.github/workflows/lintr.yml @@ -0,0 +1,55 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# lintr provides static code analysis for R. +# It checks for adherence to a given style, +# identifying syntax errors and possible semantic issues, +# then reports them to you so you can take action. +# More details at https://lintr.r-lib.org/ + +name: lintr + +on: + push: + branches: [ "main" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main" ] + schedule: + - cron: '23 5 * * 3' + +permissions: + contents: read + +jobs: + lintr: + name: Run lintr scanning + runs-on: ubuntu-latest + permissions: + contents: read # for checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup R + uses: r-lib/actions/setup-r@4e1feaf90520ec1215d1882fdddfe3411c08e492 + + - name: Setup lintr + uses: r-lib/actions/setup-r-dependencies@4e1feaf90520ec1215d1882fdddfe3411c08e492 + with: + extra-packages: lintr + + - name: Run lintr + run: lintr::sarif_output(lintr::lint_dir("."), "lintr-results.sarif") + shell: Rscript {0} + continue-on-error: true + + - name: Upload analysis results to GitHub + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: lintr-results.sarif + wait-for-processing: true diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..4bbce75 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,50 @@ +# 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.yaml + +permissions: read-all + +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@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: 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.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..960234c --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# 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] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/.gitignore b/.gitignore index e75435c..b27cb91 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ po/*~ # RStudio Connect folder rsconnect/ +.Rproj.user +docs diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..469ce16 --- /dev/null +++ b/.lintr @@ -0,0 +1,3 @@ +linters: linters_with_defaults( + line_length_linter = line_length_linter(100L) + ) diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..59f58e2 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,18 @@ +Package: eesyapi +Title: EES-y API +Version: 0.0.0.9000 +Authors@R: + person("Rich", "Bielby", , "richard.bielby@education.gov.uk", role = c("aut", "cre"), + comment = c(ORCID = "0000-0001-9070-9969")) +Description: An R package with useful utility functions for connecting to, and + processing data from, the DfE's Explore Education Statistics API. +License: MIT + file LICENSE +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.2 +URL: https://dfe-analytical-services.github.io/eesyapi +Suggests: + testthat (>= 3.0.0) +Config/testthat/edition: 3 +Imports: + httr diff --git a/LICENSE b/LICENSE index 6369f2f..fd42260 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,2 @@ -MIT License - -Copyright (c) 2024 DfE Analytical Services - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +YEAR: 2024 +COPYRIGHT HOLDER: eesyapi authors diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..4d14704 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2024 eesyapi authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..2872b31 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(eesapi_url) diff --git a/R/eesapi_url.R b/R/eesapi_url.R new file mode 100644 index 0000000..d5ecb36 --- /dev/null +++ b/R/eesapi_url.R @@ -0,0 +1,91 @@ +#' eesapi_url +#' +#' @param api_version EES API version +#' @param endpoint Name of endpoint, can be "get-summary", "get-meta", "get-data", "query-data" +#' @param dataset_id ID of data set to be connected to +#' @param dataset_version Version of data set to be connected to +#' +#' @return A string containing the URL for connecting to the EES API +#' @export +#' +#' @examples +#' eesapi_url() +eesapi_url <- function( + api_version = "1.0", + endpoint = NULL, + dataset_id = NULL, + dataset_version = NULL) { + # Check that the API version is valid + is_valid_api_version <- function(vapi) { + !grepl( + "[a-z_%+-]", + as.character(vapi), + ignore.case = TRUE + ) + } + + if (is_valid_api_version(api_version) == FALSE) { + stop( + "You have entered an invalid API version in the api_version argument. + This should be numerical values only." + ) + } + + # Check that the endpoint is either NULL or valid + is_valid_endpoint <- function(endpoint) { + endpoint %in% c("get-summary", "get-meta", "get-data", "query-data") + } + + if (!is.null(endpoint)) { + if (is_valid_endpoint(endpoint) == FALSE) { + stop( + paste( + "You have entered an invalid endpoint, this should one of:", + "get-summary, get-meta, get-data or query-data" + ) + ) + } + } + + is_valid_dataset_info <- function(dataset_id, dataset_version) { + !is.null(dataset_id) & (is.numeric(dataset_version) | is.null(dataset_version)) + } + + # Check that if endpoint is not NULL then neither is dataset_id + if (!is.null(endpoint)) { + if (is_valid_dataset_info(dataset_id, dataset_version) == FALSE) { + stop( + paste( + "You have entered invalid data set info. The following rules must be", + "met:\n", + " - dataset_id must not be NULL\n", + " - dataset_version should either be:\n", + " - NULL (gives latest version) or\n", + " - a numeric" + ) + ) + } + } + + + paste0( + "https://dev.statistics.api.education.gov.uk/api/v", + api_version, + "/data-sets/", + ifelse( + endpoint %in% c("get-summary", "get-meta", "get-data", "query-data"), + dataset_id, + "" + ), + ifelse( + endpoint %in% c("get-summary", "get-meta", "query-data"), + paste0("/", gsub("get-|-data", "", endpoint)), + "" + ), + ifelse( + !is.null(dataset_version), + paste0("?dataSetVersion=", dataset_version), + "" + ) + ) +} diff --git a/README.md b/README.md index 2dfa14c..e3c527e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,51 @@ -# eesyapi -An R package with useful utility functions for connecting to, and processing data from, the DfE's Explore Education Statistics (EES) API. +# eesyapi + + +[![R-CMD-check](https://github.com/dfe-analytical-services/eesyapi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dfe-analytical-services/eesyapi/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/dfe-analytical-services/eesyapi/branch/main/graph/badge.svg)](https://app.codecov.io/gh/dfe-analytical-services/eesyapi?branch=main) +[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) + + +An R package to support analysts in connecting to and processing data from +the DfE's explore education statistics API endpoints. + +## Installation + +eesyapi is not currently available on CRAN. For the time being you can +install the development version from GitHub. + +If you are using +[renv](https://rstudio.github.io/renv/articles/renv.html) in your +project (recommended): + +``` r +renv::install("dfe-analytical-services/eesyapi") +``` + +Otherwise: + +``` r +# install.packages("devtools") +devtools::install_github("dfe-analytical-services/eesyapi") +``` + +## Potential errors when installing + +For internal DfE users, if you get `ERROR [curl: (22) The requested URL returned error: 401]`, +and don't know why, try running `Sys.unsetenv("GITHUB_PAT")` to temporarily clear your +GitHub PAT variable. + +Then try to install again. + +If this works, then you will need to look for where that "GITHUB_PAT" variable +is being set from and remove it to permanently fix the issue, contact us for +support if you need help with this or have any other issues installing. + +## Contributing + +Ideas for eesyapi should first be raised as a [GitHub +issue](https://github.com/dfe-analytical-services/eesyapi) after which +anyone is free to write the code and create a pull request for review. + +For more details on contributing to eesyapi, see our [contributing +guidelines](https://dfe-analytical-services.github.io/eesyapi/CONTRIBUTING.html). diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..77cec78 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,6 @@ +url: https://dfe-analytical-services.github.io/eesyapi/ +template: + bootstrap: 5 + bootswatch: cyborg + bslib: + pkgdown-nav-height: 81.4468px diff --git a/eesyapi.Rproj b/eesyapi.Rproj new file mode 100644 index 0000000..69fafd4 --- /dev/null +++ b/eesyapi.Rproj @@ -0,0 +1,22 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/man/eesapi_url.Rd b/man/eesapi_url.Rd new file mode 100644 index 0000000..39e51aa --- /dev/null +++ b/man/eesapi_url.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/eesapi_url.R +\name{eesapi_url} +\alias{eesapi_url} +\title{eesapi_url} +\usage{ +eesapi_url( + api_version = "1.0", + endpoint = NULL, + dataset_id = NULL, + dataset_version = NULL +) +} +\arguments{ +\item{api_version}{EES API version} + +\item{endpoint}{Name of endpoint, can be "get-summary", "get-meta", "get-data", "query-data"} + +\item{dataset_id}{ID of dataset to be connected to} + +\item{dataset_version}{Verson of dataset to be connected to} +} +\value{ +A string containing the URL for connecting to the EES API +} +\description{ +eesapi_url +} +\examples{ +eesapi_url() +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..3482722 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(eesyapi) + +test_check("eesyapi") diff --git a/tests/testthat/test-eesapi_url.R b/tests/testthat/test-eesapi_url.R new file mode 100644 index 0000000..df0fc80 --- /dev/null +++ b/tests/testthat/test-eesapi_url.R @@ -0,0 +1,37 @@ +test_that("eesapi_url", { + expect_equal( + eesapi_url(), + "https://dev.statistics.api.education.gov.uk/api/v1.0/data-sets/" + ) + expect_error( + eesapi_url(api_version = "1.x") + ) + expect_error( + eesapi_url(endpoint = "query", dataset_id = "dummy:dataset:id") + ) + expect_error( + eesapi_url(endpoint = "query-data") + ) + expect_equal( + eesapi_url(endpoint = "query-data", dataset_id = "dummy:dataset:id"), + "https://dev.statistics.api.education.gov.uk/api/v1.0/data-sets/dummy:dataset:id/query" + ) + expect_error( + eesapi_url( + endpoint = "query-data", + dataset_id = "dummy:dataset:id", + dataset_version = "x" + ) + ) + expect_equal( + eesapi_url( + endpoint = "query-data", + dataset_id = "dummy:dataset:id", + dataset_version = 2.1 + ), + paste0( + "https://dev.statistics.api.education.gov.uk/api/v1.0/data-sets/", + "dummy:dataset:id/query?dataSetVersion=2.1" + ) + ) +})