├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitattributes ├── NAMESPACE ├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── R └── littleforecast.R ├── man └── littleforecast.Rd └── README.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(littleforecast) 4 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^TestPackage\.Rcheck$ 4 | ^TestPackage.*\.tar\.gz$ 5 | ^TestPackage.*\.tgz$ 6 | .github 7 | .git 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | *.Rproj 5 | TestPackage.Rcheck/ 6 | TestPackage*.tar.gz 7 | TestPackage*.tgz 8 | ToyPackage.Rcheck/ 9 | ToyPackage*.tar.gz 10 | ToyPackage*.tgz 11 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: TestPackage 2 | Title: This Is A Toy Package 3 | Version: 1.3 4 | Author: Eli Holmes 5 | Maintainer: 6 | Description: This is a super simple toy package for students to copy and experiment with for the short course. 7 | Depends: R (>= 3.4.1) 8 | Imports: forecast, ggplot2 9 | License: GPL-2 10 | Encoding: UTF-8 11 | LazyData: true 12 | RoxygenNote: 7.1.2 13 | -------------------------------------------------------------------------------- /R/littleforecast.R: -------------------------------------------------------------------------------- 1 | #' Forecast with Arima Model 2 | #' 3 | #' This fits an Arima model to data with forecast's auto.arima() function and plots 4 | #' a forecast with the forecast() function. 5 | #' 6 | #' @param data A vector (time series) of data 7 | #' @param nyears Number of time steps to forecast forward 8 | #' @return A plot of a forecast. 9 | #' @examples 10 | #' dat <- WWWusage 11 | #' littleforecast(dat, nyears=100) 12 | #' @export 13 | littleforecast <- function(data, nyears=10){ 14 | fit <- forecast::auto.arima(data) 15 | fc <- forecast::forecast(fit, h = nyears) 16 | ggplot2::autoplot(fc) 17 | } 18 | -------------------------------------------------------------------------------- /man/littleforecast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/littleforecast.R 3 | \name{littleforecast} 4 | \alias{littleforecast} 5 | \title{Forecast with Arima Model} 6 | \usage{ 7 | littleforecast(data, nyears = 10) 8 | } 9 | \arguments{ 10 | \item{data}{A vector (time series) of data} 11 | 12 | \item{nyears}{Number of time steps to forecast forward} 13 | } 14 | \value{ 15 | A plot of a forecast. 16 | } 17 | \description{ 18 | This fits an Arima model to data with forecast's auto.arima() function and plots 19 | a forecast with the forecast() function. 20 | } 21 | \examples{ 22 | dat <- WWWusage 23 | littleforecast(dat, nyears=100) 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/master/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | R_KEEP_PKG_SOURCE: yes 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-r@v1 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v1 25 | with: 26 | extra-packages: rcmdcheck 27 | 28 | - uses: r-lib/actions/check-r-package@v1 29 | 30 | - name: Show testthat output 31 | if: always() 32 | run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true 33 | shell: bash 34 | 35 | - name: Upload check results 36 | if: failure() 37 | uses: actions/upload-artifact@main 38 | with: 39 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 40 | path: check 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![R-CMD-check](https://github.com/RVerse-Tutorials/TestPackage/workflows/R-CMD-check/badge.svg)](https://github.com/RVerse-Tutorials/TestPackage/actions) 3 | 4 | 5 | # TestPackage 6 | A small package to experiment with. 7 | 8 | To build within RStudio, click the "Build" tab to right and then click "Install and Restart". 9 | 10 | To run the example 11 | ``` 12 | library(TestPackage) 13 | dat <- WWWusage 14 | littleforecast(dat, nyears=100) 15 | ``` 16 | 17 | # Try to add a function 18 | 19 | Add `hello.R` to the R folder. Use File > New File > R Script to create a new script file. 20 | 21 | ``` 22 | #' Hello! 23 | #' 24 | #' This just says hello. 25 | #' @export 26 | hello <- function(){ cat("HELLO") } 27 | ``` 28 | 29 | Rebuild the package and then type 30 | ``` 31 | hello() 32 | ``` 33 | 34 | Then try 35 | ``` 36 | ?hello 37 | ``` 38 | 39 | ## Add a function with a new package 40 | 41 | ``` 42 | #' dplyr example 43 | #' 44 | #' This adds a new function that needs {dplyr} 45 | #' @param col which column to average 46 | #' @export 47 | irisaverages <- function(col = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")){ 48 | col <- match.arg(col) 49 | iris$col <- iris[[col]] 50 | iris %>% dplyr::group_by(Species) %>% 51 | dplyr::summarize(mean = mean(col)) 52 | } 53 | ``` 54 | 55 | 56 | ## Installing a package that is hosted on GitHub 57 | 58 | To install, use this code. You might need to install the **devtools** package. For example, 59 | ``` 60 | devtools::install_github("RVerse-Tutorials/TestPackage") 61 | ``` 62 | 63 | --------------------------------------------------------------------------------