Skip to content

Commit

Permalink
Improvements in get_ifadv
Browse files Browse the repository at this point in the history
But still causing odd problems: tests go fine on testing, but fail on checking
  • Loading branch information
PabRod committed Aug 30, 2024
1 parent 0a16294 commit 0e48a32
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ Suggests:
rmarkdown,
testthat (>= 3.0.0),
pkgdown,
ggrepel
ggrepel,
utils
Config/testthat/edition: 3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export(report_stats)
export(theme_turnPlot)
export(tokenize)
importFrom(ggplot2,"%+replace%")
importFrom(utils,download.file)
26 changes: 18 additions & 8 deletions R/auxs.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
#' Available in the public repository:
#' https://github.com/elpaco-escience/ifadv
#'
#' @param destfile (default = "data/ifadv.rda") Destination file
#' @param destfile (default = "ifadv.rda") Destination file
#' @param clean_after (default = TRUE) Cleans the downloaded file after using it
#'
#' @return Nothing, but it loads the data into the global environment
#' @return A tibble containing the IFADV dataset
#' @importFrom utils download.file
#' @export
#'
get_ifadv <- function(destfile = "data/ifadv.rda", clean_after = TRUE) {
get_ifadv <- function(destfile = "ifadv.rda", clean_after = TRUE) {

download.file("https://raw.github.com/elpaco-escience/ifadv/main/data/ifadv.rda", destfile, quiet = TRUE)
# We are forced to download the data into a temporary file
# and load the file into memory locally
# The snippet below makes this easy to do
if(file.exists(destfile)) {
stop("The file already exists. Choose a different destfile")
} else {
file.create(destfile) # Create a dummy file
}
# Let's not forget cleaning our mess after ourselves
on.exit(if(clean_after & file.exists(destfile)) file.remove(destfile))

load(destfile, envir = .GlobalEnv) # Load it to the outside environment
download.file("https://raw.github.com/elpaco-escience/ifadv/main/data/ifadv.rda", destfile, quiet = TRUE)

on.exit( # Clean your mess after yourself
if(clean_after & file.exists(destfile)) file.remove(destfile)
)
e <- new.env()
load(destfile, envir = e) # Load it to the function environment ...
return(e[["ifadv"]]) # ... and return it as an output
}
2 changes: 1 addition & 1 deletion man/get_ifadv.Rd

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

3 changes: 1 addition & 2 deletions tests/testthat/test-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# between new and reference image. They are clickable from the test menu.

# Load the test data
get_ifadv(destfile = "../../data/ifadv.rda")
testdata <- ifadv
testdata <- get_ifadv()

#' Auxiliary decorator
#'
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-report.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## set up the test environment
get_ifadv(destfile = "../../data/ifadv.rda")
testdata <- ifadv
## Load the test data
testdata <- get_ifadv()

test_that("summary reports are accurate", {
testdata <- get_ifadv(destfile = "../../data/ifadv.rda")
expect_snapshot(
report_stats(
testdata
Expand Down
4 changes: 2 additions & 2 deletions vignettes/workflows.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ The snippet below initializes the talkr dataset using the ifadv data. For more i

```{r}
data <- init(get_ifadv(destfile = "../data/ifadv.rda"))
data <- get_ifadv()
data <- init(data)
```

Essential to any `talkr` workflow is a minimal set of data fields. These are the following:
Expand Down

0 comments on commit 0e48a32

Please sign in to comment.