Skip to content

Commit

Permalink
Merge pull request #117 from ropensci/cran_edits
Browse files Browse the repository at this point in the history
Cran edits
  • Loading branch information
slager committed Apr 15, 2024
2 parents 7b922f6 + 8d97687 commit 4f79b00
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 26 deletions.
2 changes: 2 additions & 0 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @param deps \code{logical} should we pass data objects into subsequent scripts? Default TRUE
#' @param install \code{logical} automatically install and load the package after building. Default FALSE
#' @param ... additional arguments passed to \code{install.packages} when \code{install=TRUE}.
#' @returns Character vector. File path of the built package.
#' @importFrom roxygen2 roxygenise roxygenize
#' @importFrom devtools build_vignettes build parse_deps reload
#' @importFrom usethis use_build_ignore use_rstudio proj_set use_directory
Expand Down Expand Up @@ -132,6 +133,7 @@ package_build <- function(packageName = NULL,
#' @name keepDataObjects-defunct
#' @aliases keepDataObjects
#' @param ... arguments
#' @returns Defunct. No return value.
#' @rdname keepDataObjects-defunct
#' @export
keepDataObjects <- function(...) {
Expand Down
1 change: 1 addition & 0 deletions R/dataversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @param lib.loc \code{character} path to library location.
#' @seealso \code{\link[utils]{packageVersion}}
#' @rdname data_version
#' @returns Object of class 'package_version' and 'numeric_version' specifying the DataVersion of the package
#' @note \code{dataVersion()} has been renamed to \code{data_version()}
#' @importFrom utils capture.output file_test package.skeleton packageDescription
#' @export
Expand Down
20 changes: 10 additions & 10 deletions R/digests.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

.check_dataversion_string <- function(old_data_digest, new_data_digest) {
oldwarn <- options("warn")$warn
options(warn = -1)
oldv <- strsplit(old_data_digest[["DataVersion"]], "\\.")
newv <- strsplit(new_data_digest[["DataVersion"]], "\\.")
oldv <- lapply(oldv, as.numeric)[[1]]
newv <- lapply(newv, as.numeric)[[1]]
suppressWarnings({
oldv <- strsplit(old_data_digest[["DataVersion"]], "\\.")
newv <- strsplit(new_data_digest[["DataVersion"]], "\\.")
oldv <- lapply(oldv, as.numeric)[[1]]
newv <- lapply(newv, as.numeric)[[1]]
})
if (any(is.na(oldv)) | any(is.na(newv))) {
options(warn = oldwarn)
.multilog_fatal(paste0(
"Invalid DataVersion string found ",
old_data_digest[["DataVersion"]],
Expand All @@ -36,10 +36,10 @@
existed <- names(new_digest)[names(new_digest) %in% names(old_digest)]
added <- setdiff(names(new_digest), existed)
removed <- names(old_digest)[!names(old_digest) %in% names(new_digest)]
existed <- existed[existed != "DataVersion"]
existed <- existed[existed != "DataVersion"]

if(length(existed) > 0){
changed <- names(new_digest)[ unlist(new_digest[existed]) != unlist(old_digest[existed]) ]
changed <- names(new_digest)[ unlist(new_digest[existed]) != unlist(old_digest[existed]) ]
if(length(changed) > 0){
for(name in changed){
.multilog_warn(paste(name, "has changed."))
Expand All @@ -53,15 +53,15 @@
.multilog_debug(paste(name, "was removed."))
return(FALSE)
}

for(name in added){
.multilog_debug(paste(name, "was added."))
return(FALSE)
}

return(TRUE)
};

.combine_digests <- function(new, old) {
intersection <- intersect(names(new), names(old))
difference <- setdiff(names(new), names(old))
Expand Down
26 changes: 13 additions & 13 deletions R/environments.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @return An R object.
#' @export
#' @examples
#' \dontrun{
#' \donttest{
#' if(rmarkdown::pandoc_available()){
#' ENVS <- new.env() # ENVS would be in the environment
#' # where the data processing is run. It is
Expand All @@ -25,43 +25,43 @@
#' }
#' }
datapackager_object_read <- function(name) {

# get(name, get("ENVS", parent.frame()))

#when the datapackage is being build, it will only read the object from the environment. when
# in interactive mode, it should be try to load the objects reviously generated.
# in interactive mode, it should be try to load the objects reviously generated.
# It will preferentially read the object from the the temporary folder, but if that does not exist, it will read the
# object from the the data folder
buildingPackage<-getOption("DataPackageR_packagebuilding",TRUE)


object<-try(get(name, get("ENVS", parent.frame(),inherits=FALSE),inherits=FALSE),silent=TRUE)

if( !buildingPackage && inherits(object,"try-error")){
#if the package is not being build and the object is not found in the "ENVS" environment
temp_folder_path<-file.path(tempdir(),yml_find(usethis::proj_get())[["configuration"]][["render_root"]]$tmp)

if(file.exists(objectPath<-file.path(temp_folder_path,paste0(name,".rds")))){
message('loading ',name,' from temporary folder from previous build attempt.')
object<-readRDS(objectPath)

}else if(file.exists(objectPath<-file.path(project_data_path(),paste0(name,".rda")))){
message('loading ',name,' from data directory.')
print(objectPath)
load_env<-new.env()
load(objectPath,envir = load_env)
object<-load_env[[ls(load_env)[1]]]

}else{
stop(paste(name,'not found!'))

}
}else if(inherits(object,"try-error")){
#if the package is being build and the object is not found in the "ENVS" environment,
# pass on the original error warning
stop(object[1])

}

return(object)
}
3 changes: 2 additions & 1 deletion R/processData.R
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ project_data_path <- function(file = NULL) {
#' @param path \code{character} the path to the data package source root.
#' @param install \code{logical} install and reload the package. (default TRUE)
#' @param ... additional arguments to \code{install}
#' @returns Called for side effects. Returns TRUE on successful exit.
#' @export
#' @examples
#' # A simple Rmd file that creates one data object
Expand All @@ -728,7 +729,7 @@ project_data_path <- function(file = NULL) {
#' con <- file(f)
#' writeLines("```{r}\n tbl = data.frame(1:10) \n```\n",con=con)
#' close(con)
#' \dontrun{
#' \donttest{
#' # construct a data package skeleton named "MyDataPackage" and pass
#' # in the Rmd file name with full path, and the name of the object(s) it
#' # creates.
Expand Down
1 change: 1 addition & 0 deletions R/skeleton.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#' @param r_object_names \code{vector} of quoted r object names , tables, etc. created when the files in \code{code_files} are run.
#' @param raw_data_dir \code{character} pointing to a raw data directory. Will be moved with all its subdirectories to "inst/extdata"
#' @param dependencies \code{vector} of \code{character}, paths to R files that will be moved to "data-raw" but not included in the yaml config file. e.g., dependency scripts.
#' @returns No return value, called for side effects
#' @note renamed \code{datapackage.skeleton()} to \code{datapackage_skeleton()}.
#' @importFrom crayon bold green
#' @export
Expand Down
3 changes: 3 additions & 0 deletions man/data_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/datapackage_skeleton.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/datapackager_object_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/document.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/keepDataObjects-defunct.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/package_build.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f79b00

Please sign in to comment.