Skip to content
Snippets Groups Projects
Commit 649695ac authored by Dorch's avatar Dorch
Browse files

feat: add create_fairify

Refs #1
parent c5aecdfd
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,9 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
bookdown,
usethis,
yaml
Suggests:
testthat (>= 3.0.0),
tinytex
Config/testthat/edition: 3
......@@ -2,6 +2,7 @@
export("%>%")
export(add_gitignore)
export(create_fairify)
export(getDataPath)
export(iconv_filename)
export(loadConfig)
......
#' Add .gitignore file suitable for R project
#'
#' @inheritParams create_fairify
#' @inheritParams utils::download.file
#'
#' @return `NULL`, this function is used for side effect.
#' @export
#'
#' @examples
#' tmpfile <- tempfile()
#' add_gitignore(destfile = tmpfile)
#' readLines(tmpfile)
add_gitignore <- function(url = "https://raw.githubusercontent.com/github/gitignore/main/R.gitignore",
destfile = ".gitignore") {
#' path <- tempdir()
#' add_gitignore(path = path)
#' readLines(file.path(path, ".gitignore"))
add_gitignore <- function(path = ".",
url = "https://raw.githubusercontent.com/github/gitignore/main/R.gitignore") {
destfile = file.path(path, ".gitignore")
stopifnot(download.file(url, destfile) == 0)
header <- add_comment_block("R template from:",
url,
......
#' Create a "fairified" project
#'
#' Create a package ready for fairify your project.
#'
#' @inheritParams usethis::create_package
#' @param tidy if `TRUE`, run [usethis::use_testthat()], [usethis::use_tidy_description()], and [usethis::use_tidy_dependencies()]
#' @param with_reports If `TRUE`, run `create_reports`, preparing package structure for report publications
#' @param ... Further parameters passed to [usethis::create_package]
#'
#' @return
#' @export
#'
#' @examples
#' path <- tempdir()
#' create_fairify(path, open = FALSE)
#' list.files(path)
create_fairify <- function(path, tidy = TRUE, open = rlang::is_interactive(), with_reports = TRUE, ...) {
usethis::create_package(path, rstudio = TRUE, open = FALSE, ...)
if (tidy) {
usethis::local_project(path)
usethis::use_testthat()
usethis::use_tidy_description()
}
add_gitignore(path)
if (with_reports) create_reports(path = path)
if (open) {
proj_activate(path)
}
}
......@@ -5,18 +5,17 @@
\title{Add .gitignore file suitable for R project}
\usage{
add_gitignore(
url = "https://raw.githubusercontent.com/github/gitignore/main/R.gitignore",
destfile = ".gitignore"
path = ".",
url = "https://raw.githubusercontent.com/github/gitignore/main/R.gitignore"
)
}
\arguments{
\item{path}{A path. If it exists, it is used. If it does not exist, it is
created, provided that the parent path exists.}
\item{url}{a \code{\link{character}} string (or longer vector
for the \code{"libcurl"} method) naming the URL of a resource to be
downloaded.}
\item{destfile}{a character string (or vector, see the \code{url}
argument) with the file path where the downloaded file is to be
saved. Tilde-expansion is performed.}
}
\value{
\code{NULL}, this function is used for side effect.
......@@ -25,7 +24,7 @@ add_gitignore(
Add .gitignore file suitable for R project
}
\examples{
tmpfile <- tempfile()
add_gitignore(destfile = tmpfile)
readLines(tmpfile)
path <- tempdir()
add_gitignore(path = path)
readLines(file.path(path, ".gitignore"))
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/create_fairify.R
\name{create_fairify}
\alias{create_fairify}
\title{Create a "fairified" project}
\usage{
create_fairify(
path,
tidy = TRUE,
open = rlang::is_interactive(),
with_reports = TRUE,
...
)
}
\arguments{
\item{path}{A path. If it exists, it is used. If it does not exist, it is
created, provided that the parent path exists.}
\item{tidy}{if \code{TRUE}, run \code{\link[usethis:use_testthat]{usethis::use_testthat()}}, \code{\link[usethis:tidyverse]{usethis::use_tidy_description()}}, and \code{\link[usethis:tidyverse]{usethis::use_tidy_dependencies()}}}
\item{open}{If \code{TRUE}, \link[usethis:proj_activate]{activates} the new project:
\itemize{
\item If using RStudio desktop, the package is opened in a new session.
\item If on RStudio server, the current RStudio project is activated.
\item Otherwise, the working directory and active project is changed.
}}
\item{with_reports}{If \code{TRUE}, run \code{create_reports}, preparing package structure for report publications}
\item{...}{Further parameters passed to \link[usethis:create_package]{usethis::create_package}}
}
\description{
Create a package ready for fairify your project.
}
\examples{
path <- tempdir()
create_fairify(path, open = FALSE)
list.files(path)
}
# 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(fairify)
test_check("fairify")
test_that("create_fairify works", {
path <- tempfile()
create_fairify(path, open = FALSE)
project <- basename(path)
expect_true(file.exists(file.path(path, paste0(project, ".Rproj"))))
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment