Skip to content

Commit

Permalink
Passing r cmd check
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Ross committed Nov 14, 2023
1 parent cad2fa3 commit 49a605b
Show file tree
Hide file tree
Showing 56 changed files with 881 additions and 220 deletions.
14 changes: 7 additions & 7 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
^\.github$
^CODE_OF_CONDUCT\.md$
^LICENSE\.md$
^man/commits_range\.Rd$
^man/blob_to_file\.Rd$
^man/install_minio\.Rd$
^man/sys_tempdir\.Rd$
^man/sys_tempfile\.Rd$
^man/as_repo\.Rd$
^man/as_commit\.Rd$
^CITATION\.cff$
^codemeta.json$
^.lintr$
^_pkgdown\.yml$
^docs$
^pkgdown$
^inst/scratch$
^inst/mc$
2 changes: 0 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:
Expand Down
112 changes: 108 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,111 @@
.Rproj.user
inst/doc
inst/scratch
inst/mc
docs
tests/testthat/*.log
### R ###
# History files
*Rhistory
.Rhistory
.Rdata
.Rapp.history
.Rproj.user
.RData
.Ruserdata
# Session Data files
# User-specific files
# Example code in package build process
*-Ex.R
# Output files from R CMD build
/*.tar.gz
# Output files from R CMD check
/*.Rcheck/
# RStudio files
.Rproj.user/
# produced vignettes
vignettes/*.html
vignettes/*.pdf
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth
.DS_Store
# knitr and R markdown default cache directories
*_cache/
/cache/
# Temporary files created by R markdown
*.utf8.md
*.knit.md
.quarto
inst/doc
### R.Bookdown Stack ###
# R package: bookdown caching files
/*_files/
# End of https://www.toptal.com/developers/gitignore/api/r,c++,macos,microsoftoffice
### C++ ###
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Linker files
*.ilk
# Debugger Files
*.pdb
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### MicrosoftOffice ###
*.tmp
# Word temporary
~$*.doc*
# Word Auto Backup File
Backup of *.doc*
# Excel temporary
~$*.xls*
# Excel Backup File
*.xlk
# PowerPoint temporary
~$*.ppt*
# Visio autosave temporary files
*.~vsd*


# Created by https://www.toptal.com/developers/gitignore/api/r,c++,macos,microsoftoffice
# Edit at https://www.toptal.com/developers/gitignore?templates=r,c++,macos,microsoftoffice
51 changes: 28 additions & 23 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,42 @@ Authors@R: c(
person("Noam", "Ross", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-2136-0000")),
person("EcoHealth Alliance", role = c("cph", "fnd"))
)
Description: Tools working with the history of version-controlled projects,
)
Description: The 'relic' package provides tools for extracting files and
objects from the history of a git repository. It is a high-level
interface designed to enable comparison of objects in reproducible
research workflows, especially pipelines that use the 'targets'
package.
License: MIT + file LICENSE
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace", "devtag::dev_roclet"))
RoxygenNote: 7.2.3
URL: https://ecohealthalliance.github.io/relic,
https://ecohealthalliance.r-universe.dev/relic
BugReports: https://github.com/ecohealthalliance/relic/issues
Imports:
git2r,
fs,
git2r,
rlang
Suggests:
igraph,
callr,
devtag,
glue,
knitr,
lintr,
minioclient,
pkgcheck,
rmarkdown,
spelling,
targets,
testthat (>= 3.0.0),
devtag,
pkgcheck,
lintr,
processx,
paws,
httr,
autotest,
callr,
spelling
withr
VignetteBuilder:
knitr
Remotes:
ropensci/git2r,
moodymudskipper/devtag,
ropensci-review-tools/pkgcheck
cboettig/minioclient#14,
ropensci-review-tools/pkgcheck,
ropensci/git2r
Config/testthat/edition: 3
URL: https://ecohealthalliance.github.io/relic, https://ecohealthalliance.r-universe.dev/relic
BugReports: https://github.com/ecohealthalliance/relic/issues
VignetteBuilder: knitr
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace",
"devtag::dev_roclet"))
RoxygenNote: 7.2.3
13 changes: 8 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Generated by roxygen2: do not edit by hand

S3method(relic,git_blob)
S3method(relic,git_tree)
export(commits_between)
export(dir_ls_version)
export(dir_ls_versions)
export(file_copy_version)
export(file_copy_versions)
export(file_read_version)
export(file_read_versions)
export(graph_from_commits)
export(graph_from_git_repository)
export(relic)
export(tar_load_version)
export(relic_cache)
export(relic_cache_clear)
export(tar_exists_version)
export(tar_exists_version_raw)
export(tar_meta_version)
export(tar_read_raw_version)
export(tar_read_raw_versions)
export(tar_read_version)
export(tar_read_versions)
import(fs)
import(git2r)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# relic (development version)

* Started adding tests

# relic 0.0.1

* Initial proof of concept
8 changes: 6 additions & 2 deletions R/commits_between.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#'
#' @param from A commit object or revision string. A string of the form
#' 'from...to' may also be passed, in which case the commits between the two
#' revision strings are used and the `to` argument is ignored.
#' revision strings are used and the `to` argument is ignored. If a list of commits
#' is passed, these commits are used rather than calculating the commits between.
#' @param to A commit object or reference
#' @param filter_file The path to a file relative to the git directory. If not NULL,
#' only commits modifying this file will be returned. Note that modifying
Expand All @@ -24,6 +25,9 @@
#' @export
commits_between <- function(from, to = NULL, filter_file = NULL, repo = ".") {
repo <- as_repo(repo)
if (is.list(from) && all(vapply(from, is_commit, logical(1)))) {
return(commits)
}
range <- commits_range(from, to, repo)
if (is.null(range[[2]])) {
return(list(range[[1]]))
Expand Down Expand Up @@ -66,7 +70,7 @@ commits_between <- function(from, to = NULL, filter_file = NULL, repo = ".") {
}

#' Parse 1 or 2 commits or revision strings into two commits
#' @dev
#' @noRd
commits_range <- function(from, to, repo) {
if (is.character(from)) {
refs <- strsplit(from, "...", fixed = TRUE)[[1]]
Expand Down
13 changes: 7 additions & 6 deletions R/dir_ls_version.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#' List files and folders in a git repository
#'
#' @inheritParams file_read_version
#' @param param all If TRUE hidden files are also returned
#' @param all If TRUE hidden files are also returned
#' @param recurse If TRUE recurse fully, if a positive number the number of levels to recurse
#' @param type One or more of "any", "file", "directory", "symlink", or "submodule"
#' @param regexp A regular expression (e.g. ⁠[.]csv$⁠) passed on to grep() to filter paths.
#' @param glob A wildcard aka globbing pattern (e.g. *.csv⁠) passed on to grep() to filter paths
#' @param regexp A regular expression (e.g. '\\.csv$'⁠) passed on to grep() to filter paths.
#' @param glob A wildcard aka globbing pattern (e.g. '*.csv'⁠) passed on to grep() to filter paths
#' @param invert If TRUE, return paths that do not match the pattern or glob
#' @return A character vector of paths
#' @export
dir_ls_version <- function(path = ".", ref = "HEAD", all = FALSE, recurse = FALSE, type = "any", regexp = NULL, glob = NULL, repo = ".") {
tree <- get_obj_at_commit(path, ref, repo)
dir_ls_version <- function(path = ".", ref = "HEAD", all = FALSE, recurse = FALSE, type = "any", regexp = NULL, glob = NULL, invert = FALSE, repo = ".") {
commit <- as_commit(ref, repo)
tree <- get_obj_at_commit(path, commit)
if (!is_tree(tree)) abort("Path is not a directory")
if (!is.numeric(recurse)) recurse <- if (recurse) Inf else 0

Expand All @@ -27,7 +28,7 @@ dir_ls_version <- function(path = ".", ref = "HEAD", all = FALSE, recurse = FALS
if (!all) {
paths <- path_filter(paths, regexp = "^[^\\.].*$")
}
paths <- path_filter(paths, glob = glob, regexp = regexp)
paths <- path_filter(paths, glob = glob, regexp = regexp, invert = invert)
paths
}

Expand Down
62 changes: 62 additions & 0 deletions R/example_repo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#' Set up a testing and example repository
#'
#' This function generates a repository with a commit history that can be used
#' for testing and examples.
#' @param dir Path to the directory where the repository should be created
#' @param reporter the reporter to use when building targets with [targets::tar_make()]. Defaults to "silent".
#' @param s3 Whether the repository should use S3 storage for targets. Note that
#' the S3 endpoint and bucket must already be available.
create_example_repo <- function(dir = fs::file_temp("relic_example_"), reporter = "silent", s3 = TRUE) {
check_installed(c("targets", "glue"))
if (dir_exists(dir)) dir_delete(dir)
dir_create(dir)
od <- setwd(dir)
on.exit(setwd(od))
repo <- git2r::init()
# Configure the repository to use a generic user name and email address
git2r::config(repo, user.name = "relic-bot", user.email = "[email protected]")

# Create a minimal _targets.R file
write_to_file(
"_targets.R",
'library(targets)
list(
tar_target(cars, mtcars, repository = "local"),
tar_target(cars_csv, {name <- "cars.csv"; write.csv(cars, name); name}, format = "file", repository = "local")
)
'
)

stamp("initial-target-file")

targets::tar_make(reporter = reporter)
append_to_file("_targets/.gitignore", c("!objects/\n!objects/*"))
stamp("first-targets-run")

overwrite_at_line(
"_targets.R", 3,
"tar_target(cars, rbind(mtcars, mtcars)),"
)
targets::tar_make(reporter = reporter)
stamp("longer-cars")

if(s3) {
insert_lines_at(
"_targets.R", 2,
'Sys.setenv(AWS_ACCESS_KEY_ID="minioadmin", AWS_SECRET_ACCESS_KEY="minioadmin")
tar_option_set(
resources = tar_resources(
aws = tar_resources_aws(
bucket = "relic-test",
prefix = "_targets",
endpoint = "http://localhost:9000"
)),
repository = "aws"
)
')
targets::tar_make(reporter = reporter)
stamp("setup-s3")
}

dir
}
Loading

0 comments on commit 49a605b

Please sign in to comment.