diff --git a/.Rbuildignore b/.Rbuildignore index bb3d9fc..3faeeba 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,3 +5,4 @@ ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..63cbb18 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,35 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-pandoc@v1 + + - uses: r-lib/actions/setup-r@v1 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v1 + with: + extra-packages: pkgdown + needs: website + + - name: Deploy package + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.gitignore b/.gitignore index eb91194..cdc5d6d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ .DS_Store inst/doc -docs diff --git a/DESCRIPTION b/DESCRIPTION index 9d86a7b..cda39af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,3 +17,4 @@ Suggests: knitr, rmarkdown VignetteBuilder: knitr +URL: https://gdmcdonald.github.io/once diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/docs/.nojekyll @@ -0,0 +1 @@ + diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..d885f71 --- /dev/null +++ b/docs/404.html @@ -0,0 +1,93 @@ + + +
+ + + + +YEAR: 2022 +COPYRIGHT HOLDER: Gordon McDonald ++ +
Copyright (c) 2022 once authors
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+An R package that makes it easy to execute expensive operations only once.
+Using once()
you can wrap an expensive operation so that output is saved to disk. If the file exists, it won’t run again, it will just load the saved version.
Eg. instead of
+file_path <- "saved_models/my_trained_models.Rds"
+
+if (file.exists(file_path)){
+
+ my_number <- readRDS(file = file_path)
+
+} else {
+
+ my_number <-
+ runif(1e8) %>% # some expensive operation
+ mean()
+ # or ML model training such as `my_trained_models <- train_models_function(...)`
+
+ saveRDS(my_number, file = file_path)
+}
+it would look like
+my_number <-
+ runif(1e8) %>% # some expensive operation
+ mean() %>%
+ once(file_path = "saved_random_number.Rds") # only do it once, save output to this file.
+#install.packages("devtools")
+devtools::install_github("gdmcdonald/once")
+library(once)
+
+ All functions+ + |
+ |
---|---|
+ + | +Execute Expensive Operations Only Once |
+
once.Rd
The once()
function allows you to easily execute expensive compute operations only once, and save the resulting object to disk.
once(expr, file_path = NULL, rerun = FALSE)
The expensive expression to evaluate
File path for saving the output object as an Rds file. Defaults to an auto-generated file in the 'saved_objects' folder in current project's directory. Note that if no filename is provided it will rerun and re-save every time!
Rerun the expression anyway and save the result? Defaults to false.
the results of expr
+pipe.Rd
See magrittr::%>%
for details.
lhs %>% rhs
A value or the magrittr placeholder.
A function call using the magrittr semantics.
The result of calling rhs(lhs)
.