From e26d2558d14d7f69b97e961d133810eb1bcd5a0f Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 29 Aug 2023 17:14:39 +0800 Subject: [PATCH] Add basic pipeline for data fetching Signed-off-by: Liang Zhang --- NAMESPACE | 1 + R/use_targets.R | 31 ++++++++++++++++++++++++++++ inst/pipelines/use_targets.R | 40 ++++++++++++++++++++++++++++++++++++ man/use_targets.Rd | 15 ++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 R/use_targets.R create mode 100644 inst/pipelines/use_targets.R create mode 100644 man/use_targets.Rd diff --git a/NAMESPACE b/NAMESPACE index 1c1fe026..e41a450f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(fetch_data) export(fetch_parameterized) export(prepare_fetch_data) export(preproc_data) +export(use_targets) export(wrangle_data) import(rlang) import(tidyselect) diff --git a/R/use_targets.R b/R/use_targets.R new file mode 100644 index 00000000..c532285d --- /dev/null +++ b/R/use_targets.R @@ -0,0 +1,31 @@ +#' Create standard data fetching targets pipeline script +#' +#' This function creates a standard data fetching targets pipeline script +#' for you to fill in. +#' +#' @return NULL (invisible). This function is called for its side effects. +#' @export +use_targets <- function() { + script <- "_targets.R" + if (file.exists(script)) { + cli::cli_alert_info( + sprintf("File {.file %s} exists. Stash and retry.", script) + ) + return(invisible()) + } + copy_success <- file.copy( + system.file( + "pipelines", "use_targets.R", + package = "tarflow.iquizoo" + ), + script + ) + if (!copy_success) { + cli::cli_alert_danger("Sorry, copy template failed.") + return(invisible()) + } + cli::cli_alert_success( + sprintf("File {.file %s} crated successfully.", script) + ) + return(invisible()) +} diff --git a/inst/pipelines/use_targets.R b/inst/pipelines/use_targets.R new file mode 100644 index 00000000..60267af8 --- /dev/null +++ b/inst/pipelines/use_targets.R @@ -0,0 +1,40 @@ +# Created by tarflow.iquizoo::use_targets(). +# Follow the comments below to fill in this target script. +# Then follow the manual to check and run the pipeline: +# https://books.ropensci.org/targets/walkthrough.html#inspect-the-pipeline + +# Load packages required to define the pipeline: +library(targets) +# library(tarchetypes) # Load other packages as needed. + +# Set target options: +tar_option_set( + packages = c("tarflow.iquizoo", "preproc.iquizoo") # packages that your targets need to run + # format = "qs", # Optionally set the default storage format. qs is fast. + # + # For distributed computing in tar_make(), supply a {crew} controller + # as discussed at https://books.ropensci.org/targets/crew.html. + # Choose a controller that suits your needs. For example, the following + # sets a controller with 2 workers which will run as local R processes: + # + # controller = crew::crew_controller_local(workers = 2) + # + # Set other options as needed. +) + +# Run the R scripts in the R/ folder with your custom functions: +tar_source() +# source("other_functions.R") # Source other scripts as needed. + +tbl_params <- tibble::tribble( + ~course_name, ~course_period, + # replace course name and course period with your own + "# COURSE NAME", "# COURSE PERIOD" +) + +# Replace the target list below with your own: +list( + # change what to scores or raw_data if you want to + tarflow.iquizoo::prepare_fetch_data(tbl_params, what = "all") + # more targets goes here +) diff --git a/man/use_targets.Rd b/man/use_targets.Rd new file mode 100644 index 00000000..597ac6a0 --- /dev/null +++ b/man/use_targets.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/use_targets.R +\name{use_targets} +\alias{use_targets} +\title{Create standard data fetching targets pipeline script} +\usage{ +use_targets() +} +\value{ +NULL (invisible). This function is called for its side effects. +} +\description{ +This function creates a standard data fetching targets pipeline script +for you to fill in. +}