Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base packages attached by default #132

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Depends: R (>= 3.5.0)
Imports:
digest,
knitr,
utils,
rmarkdown,
desc,
yaml,
Expand Down
10 changes: 0 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ importFrom(rmarkdown,render)
importFrom(roxygen2,roxygenise)
importFrom(roxygen2,roxygenize)
importFrom(rprojroot,is_r_package)
importFrom(stats,runif)
importFrom(stats,setNames)
importFrom(stringr,str_trim)
importFrom(usethis,create_package)
importFrom(usethis,proj_get)
Expand All @@ -67,14 +65,6 @@ importFrom(usethis,use_build_ignore)
importFrom(usethis,use_data_raw)
importFrom(usethis,use_directory)
importFrom(usethis,use_rstudio)
importFrom(utils,capture.output)
importFrom(utils,file_test)
importFrom(utils,getSrcref)
importFrom(utils,install.packages)
importFrom(utils,modifyList)
importFrom(utils,package.skeleton)
importFrom(utils,packageDescription)
importFrom(utils,packageVersion)
importFrom(withr,with_options)
importFrom(yaml,as.yaml)
importFrom(yaml,read_yaml)
Expand Down
3 changes: 1 addition & 2 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#' @importFrom usethis use_build_ignore use_rstudio proj_set use_directory
#' @importFrom rprojroot is_r_package
#' @importFrom rmarkdown pandoc_available
#' @importFrom utils install.packages
#' @importFrom yaml read_yaml
#' @importFrom futile.logger flog.logger flog.trace appender.file flog.debug flog.info flog.warn flog.error flog.fatal flog.appender flog.threshold INFO TRACE appender.console appender.tee
#' @importFrom knitr knit spin
Expand Down Expand Up @@ -112,7 +111,7 @@ package_build <- function(packageName = NULL,
)
# try to install and then reload the package in the current session
if (install) {
install.packages(location, repos = NULL, type = "source", ...)
utils::install.packages(location, repos = NULL, type = "source", ...)
}
.next_steps()
return(location)
Expand Down
1 change: 0 additions & 1 deletion R/dataversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#' @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
#' @examples
#' if(rmarkdown::pandoc_available()){
Expand Down
2 changes: 1 addition & 1 deletion R/parseDocumentation.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.doc_parse <- function(all_r_files) {
sources <- lapply(all_r_files, function(x) parse(x, keep.source = TRUE))
docs <- lapply(sources, function(x) try(comments(getSrcref(x))))
docs <- lapply(sources, function(x) try(comments(utils::getSrcref(x))))
docs <- lapply(docs, function(x) lapply(x, as.character))
indx <- lapply(
lapply(
Expand Down
3 changes: 1 addition & 2 deletions R/processData.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#' @return logical TRUE if successful, FALSE, if not.
#' @importFrom desc desc
#' @importFrom rmarkdown render
#' @importFrom utils getSrcref modifyList
#' @importFrom usethis proj_set proj_get
DataPackageR <- function(arg = NULL, deps = TRUE) {
if (! getOption('DataPackageR_verbose', TRUE)){
Expand Down Expand Up @@ -775,7 +774,7 @@ document <- function(path = ".", install = FALSE, ...) {
)
# try to install and then reload the package in the current session
if (install) {
install.packages(location, repos = NULL, type = "source", ...)
utils::install.packages(location, repos = NULL, type = "source", ...)
}
return(TRUE)
}
1 change: 0 additions & 1 deletion R/roxygen2_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ comments <- function(refs) {
com
}

#' @importFrom stats setNames
#' @importFrom stringr str_trim
read.description <- function(file) {
dcf <- read.dcf(file, keep.white = "Authors@R")
Expand Down
4 changes: 1 addition & 3 deletions R/use.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#'
#' @return invisibly returns TRUE for success. Stops on failure.
#' @importFrom usethis proj_get proj_set create_package use_data_raw
#' @importFrom utils file_test
#' @export
#'
#' @examples
Expand Down Expand Up @@ -77,7 +76,6 @@ use_raw_dataset <- function(path = NULL, ignore = FALSE) {
#'
#' @return invisibly returns TRUE for success. Stops on failure.
#' @importFrom usethis proj_get proj_set create_package use_data_raw
#' @importFrom utils file_test packageVersion
#' @export
#'
#' @examples
Expand Down Expand Up @@ -353,7 +351,7 @@ use_data_object <- function(object_name = NULL) {

.yaml_load_utf8 <- function(string, ...) {
string <- paste(string, collapse = "\n")
if (packageVersion("yaml") >= "2.1.14") {
if (utils::packageVersion("yaml") >= "2.1.14") {
yaml::yaml.load(string, ...)
}
else {
Expand Down
1 change: 0 additions & 1 deletion R/yamlR.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#' @description Edit a yaml configuration file via an API.
#' @details Add, remove files and objects, enable or disable parsing of specific files, list objects or files in a yaml config, or write a config back to a package.
#' @importFrom yaml yaml.load_file as.yaml write_yaml
#' @importFrom stats runif
#' @importFrom withr with_options
#' @export
#'
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-datapackager-object-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("data objects can be read across scripts", {
# force = TRUE,
# r_object_names = "cars_over_20"
# )
#
#
ENVS <- new.env()
dataenv <- new.env()
assign("foo", 100, ENVS)
Expand Down Expand Up @@ -47,7 +47,7 @@ test_that("data objects are saved incrementally in render_root", {
package_build(
file.path(tempdir(), "subsetCars")
)
expect_true(file_test("-f",file.path(tempdir(),DataPackageR::yml_find(file.path(tempdir(),"subsetCars"))[["configuration"]][["render_root"]][["tmp"]],"cars_over_20.rds")))
expect_true(utils::file_test("-f",file.path(tempdir(),DataPackageR::yml_find(file.path(tempdir(),"subsetCars"))[["configuration"]][["render_root"]][["tmp"]],"cars_over_20.rds")))
})


Expand All @@ -65,20 +65,20 @@ test_that("data objects can be read from render_root or the data dir", {
package_build(
file.path(tempdir(), "subsetCars")
)

#create object that doesn't exist in temporary file, so datapackager_object_read is forced to look in the data dir
file.copy(file.path(tempdir(),"subsetCars","data","cars_over_20.rda"),
file.path(tempdir(), "subsetCars","data","cars_over_20_2.rda"))

original<-readRDS(file.path(tempdir(),DataPackageR::yml_find(file.path(tempdir(),"subsetCars"))[["configuration"]][["render_root"]][["tmp"]],"cars_over_20.rds"))

expect_identical(suppressMessages(datapackager_object_read("cars_over_20")),original)
expect_identical(datapackager_object_read("cars_over_20_2"),original)

#check if the reading will try to read from the ENV
options("DataPackageR_packagebuilding" = TRUE)
on.exit({options("DataPackageR_packagebuilding" = FALSE)})

expect_error(datapackager_object_read("cars_over_20"))

})
8 changes: 4 additions & 4 deletions tests/testthat/test-edge-cases.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test_that("package built in different edge cases", {
)
test_env <- new.env()
assign('test_obj', pi, envir = test_env)
package.skeleton("foo", path = tempdir(), environment = test_env)
utils::package.skeleton("foo", path = tempdir(), environment = test_env)
suppressWarnings(expect_error(
DataPackageR:::DataPackageR(
file.path(tempdir(), "foo")
Expand Down Expand Up @@ -89,7 +89,7 @@ test_that("package built in different edge cases", {
)


package.skeleton("foo", path = tempdir(), environment = test_env, force = TRUE)
utils::package.skeleton("foo", path = tempdir(), environment = test_env, force = TRUE)
expect_error(yml_find(file.path(tempdir(), "foo")))
dir.create(file.path(tempdir(), "foo", "data-raw"))
unlink(file.path(tempdir(), "foo", "DESCRIPTION"))
Expand Down Expand Up @@ -169,7 +169,7 @@ test_that("package built in different edge cases", {
force = TRUE,
recursive = TRUE
)
package.skeleton("foo", path = tempdir(), environment = test_env, force = TRUE)
utils::package.skeleton("foo", path = tempdir(), environment = test_env, force = TRUE)
DataPackageR:::.multilog_setup(file.path(tempdir(),"test.log"))
DataPackageR:::.multilog_thresold(INFO, TRACE)

Expand Down Expand Up @@ -297,7 +297,7 @@ test_that("package built in different edge cases", {
force = TRUE,
recursive = TRUE
)
package.skeleton("foo", path = tempdir(), environment = test_env, force = TRUE)
utils::package.skeleton("foo", path = tempdir(), environment = test_env, force = TRUE)
dir.create(file.path(tempdir(), "foo", "data-raw"))
suppressWarnings(
expect_error(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ withr::with_options(list(DataPackageR_verbose = TRUE),{
})
test_that(".multilog_info", {
expect_output(DataPackageR:::.multilog_info("message"), "INFO .* message")
expect_true(file_test("-f", file.path(tempdir(), "test.log")))
expect_true(utils::file_test("-f", file.path(tempdir(), "test.log")))
})
test_that(".multilog_error", {
expect_output(DataPackageR:::.multilog_error("message"), "ERROR .* message")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-r-processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_that("R file processing works and creates vignettes", {
v <- vignette(package = "rfiletest", lib.loc = temp_libpath)

expect_equal(v$results[, "Item"], "rfileTest")
expect_true(file_test("-f", file.path(tempdir,"rfiletest","inst","doc","rfileTest.pdf")))
expect_true(utils::file_test("-f", file.path(tempdir,"rfiletest","inst","doc","rfileTest.pdf")))
unlink(file.path(tempdir, "rfiletest"),
recursive = TRUE,
force = TRUE
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-use_raw_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test_that("use_raw_data works as expected", {
)
expect_true(use_raw_dataset(myfile))
expect_true(use_raw_dataset(myfile, ignore = TRUE))
expect_true(file_test(
expect_true(utils::file_test(
"-f",
file.path(
tempdir(),
Expand Down Expand Up @@ -74,14 +74,14 @@ test_that("use_processing_script works as expected", {
expect_false(any(grepl("foo",readLines(normalizePath(file.path(tempdir(),"subsetCars20","data-raw","newScript.Rmd"), winslash = "/")))))
expect_true(use_processing_script("newScript.Rmd", title = "foo", overwrite = TRUE))
expect_true(any(grepl("foo",readLines(normalizePath(file.path(tempdir(),"subsetCars20","data-raw","newScript.Rmd"), winslash = "/")))))
expect_true(use_processing_script("newScript.Rmd",

expect_true(use_processing_script("newScript.Rmd",
title = "foo", author = "bar", overwrite = TRUE))
expect_true(use_processing_script("newScript.Rmd", author = "bar", overwrite = TRUE))

expect_true(use_processing_script("newScript.R", overwrite = TRUE))
expect_true(use_processing_script("newScript.R", title = "foo", overwrite = TRUE))
expect_true(use_processing_script("newScript.R",
expect_true(use_processing_script("newScript.R",
title = "foo", author = "bar", overwrite = TRUE))
expect_true(use_processing_script("newScript.R", author = "bar", overwrite = TRUE))
expect_equal(readLines(
Expand Down Expand Up @@ -144,8 +144,8 @@ test_that(".update_header", {
)

con <- file(file.path(tempdir(), "foo.Rmd"), open = "wt")
writeLines(text =
c("---", "title: My Title", "author: My Name", "---"),
writeLines(text =
c("---", "title: My Title", "author: My Name", "---"),
con = con)
close(con)
DataPackageR:::.update_header(
Expand Down Expand Up @@ -188,12 +188,12 @@ test_that(".partition_r_front_matter", {
DataPackageR:::.partition_r_front_matter(test_string2)$front_matter,
NULL
)

expect_equal(DataPackageR:::.partition_r_front_matter(
c("#' ---","author:Greg Finak","#' ---","body")),
list(front_matter = c("#' ---","author:Greg Finak","#' ---"),
body = "body"))

expect_equal(
is.null(
DataPackageR:::.partition_r_front_matter(test_string3)$body
Expand Down Expand Up @@ -273,12 +273,12 @@ test_that(".partition_rmd_front_matter", {
DataPackageR:::.partition_rmd_front_matter(test_string4)$front_matter,
NULL
)

expect_equal(DataPackageR:::.partition_rmd_front_matter(
c("---","author:Greg Finak","---","body")),
list(front_matter = c("---","author:Greg Finak","---"),
body = "body"))

expect_equal(
is.null(
DataPackageR:::.partition_rmd_front_matter(test_string5)$front_matter
Expand Down