Closed mianzg closed 5 months ago
We may refer to tests in usethis
package to write our own tests: https://github.com/r-lib/usethis/tree/main/tests/testthat
@mianzg
In the DESCRIPTION file, please align the 'Description' text with the rest of the text above. After that, I should be able to install the package from GitHub. Please also edit the workflow 'Data repository set-up' -> 3. -> v. devtools::install_github("openwashdata-dev/washr")
@mianzg Here is the template I like to use for data_processing.R
:
# Description -------------------------------------------------------------
# R script to process uploaded raw data into a tidy, analysis-ready data frame
# Load packages -----------------------------------------------------------
library(tidyverse)
library(openwashdata)
library(readxl)
library(janitor)
library(dplyr)
# Read data -------------------------------------------------------------
data_in <- read_csv("data-raw/dataset.csv") |>
as_tibble()
codebook <- read_excel("data-raw/codebook.xlsx") |>
clean_names()
# Tidy data ---------------------------------------------------------------
# Write data -------------------------------------------------------------
usethis::use_data(dataset, overwrite = TRUE)
fs::dir_create(here::here("inst", "extdata"))
write_csv(dataset, here::here("inst", "extdata", "dataset.csv"))
openxlsx::write.xlsx(dataset, here::here("inst", "extdata", "dataset.xlsx"))
Thanks! I incorporate it into the template here https://github.com/openwashdata-dev/washr/pull/1/commits/9bd9158bb64f2ae41cd58b45482be42fab35e237
The "Read data" part are in comments to be as a suggestion.
Please also review the function update_description
, which you may need to reinstall the package with devtools::install_github("openwashdata-dev/washr@dev")
@mianzg
setup_rawdata.R
file, I would just change the documentation to
#' Create the data-raw directory with a data-processing.R template
#'
#' @description
#' `setup_rawdata()` creates a directory for raw data and provides an example script
#' named `data_processing.R` for importing, processing and exporting the data. When running this function,
#' you may be prompted to override an existing `data_processing.R` file, which is initially
#' generated as empty. It's recommended to choose to override it, especially for openwashdata
#' dataset package development. The template assumes that the dataset name is the same as
#' the data package name.
#'
#' @export
#'
#' @examples
#' \dontrun{
#' setup_rawdata()
#' # When prompted, select "yes" or a similar option to override the data_processing.R file
#' }
#'
update_description.R
file, I would modify the documentation to
#' Update the default DESCRIPTION to adhere to openwashdata style
#'
#' @description
#' This function updates the DESCRIPTION file of an R package to comply with openwashdata standards.
#' It adds or modifies fields such as doculicense, language, date, URL, etc.
#'
#' @param file File path to the R package containing the DESCRIPTION file. Defaults to the current working directory.
#' @param github_user URL path to the GitHub user or organization hosting the package. Defaults to https://github.com/openwashdata.
#'
#' @export
#'
#' @examples
#' \dontrun{
#' update_description()
#' }
#'
Concerning the testing of the functions, please have a look at the test_setup_rawdata.R
and test_update_description.R
files I just created, which are located in the tests/testthat
directory. Everything seems to be working correctly! 😊
@mianzg
- Concerning the
setup_rawdata.R
file, I would just change the documentation to#' Create the data-raw directory with a data-processing.R template #' #' @description #' `setup_rawdata()` creates a directory for raw data and provides an example script #' named `data_processing.R` for importing, processing and exporting the data. When running this function, #' you may be prompted to override an existing `data_processing.R` file, which is initially #' generated as empty. It's recommended to choose to override it, especially for openwashdata #' dataset package development. The template assumes that the dataset name is the same as #' the data package name. #' #' @export #' #' @examples #' \dontrun{ #' setup_rawdata() #' # When prompted, select "yes" or a similar option to override the data_processing.R file #' } #'
- As for the
update_description.R
file, I would modify the documentation to#' Update the default DESCRIPTION to adhere to openwashdata style #' #' @description #' This function updates the DESCRIPTION file of an R package to comply with openwashdata standards. #' It adds or modifies fields such as doculicense, language, date, URL, etc. #' #' @param file File path to the R package containing the DESCRIPTION file. Defaults to the current working directory. #' @param github_user URL path to the GitHub user or organization hosting the package. Defaults to https://github.com/openwashdata. #' #' @export #' #' @examples #' \dontrun{ #' update_description() #' } #'
Concerning the testing of the functions, please have a look at the
test_setup_rawdata.R
andtest_update_description.R
files I just created, which are located in thetests/testthat
directory. Everything seems to be working correctly! 😊
I added the suggestions! For documentation suggestion, I think you can directly make the changes on the files and commit them and do not need to ask for my review
For the tests, I borrowed the code from usethis
so it creates a temporary package before running into the tests. The code is in tests/testthat/helper.R
, which follows usethis
package structure too.
With this, we can actually test on stuff expected on the created data package instead of the washr
package. For instance, the test_setup_rawdata()
is changed into:
options(usethis.quiet = TRUE)
test_that("File and directory are created", {
create_local_package() # Create a temporary pkg
rlang::local_interactive(FALSE) #Disable interactive R
print(getwd())
washr::setup_rawdata()
expect_true(file.exists("data-raw/data_processing.R"))
})
unlink("data-raw", recursive = TRUE)
We deleted the tests on checking file size because the name of the data package varies and thus the generated file will have different sizes.
Please test and review the following code and file @margauxgo
R/setup_rawdata.R inst/templates/data_processing.R