diff --git a/.Rbuildignore b/.Rbuildignore index 62497a1..8bee5ea 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,7 +6,9 @@ ^pkgdown$ ^.lintr$ .vscode$ +^\.github$ terraform/ DEVELOPER.md ^README\.Rmd$ ^CODE_OF_CONDUCT\.md$ + 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..919767a --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + release: + types: [published] + workflow_dispatch: + +name: pkgdown.yaml + +permissions: read-all + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + GARGLE_ENCRYPTION_KEY: ${{ secrets.GARGLE_ENCRYPTION_KEY }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = TRUE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/DESCRIPTION b/DESCRIPTION index 23c1a00..61d7bc0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,4 +40,6 @@ Suggests: testthat (>= 3.0.0), zoo VignetteBuilder: quarto +URL: https://nih-cfde.github.io/programets/ +BugReports: https://github.com/nih-cfde/programets/issues Config/testthat/edition: 3 diff --git a/_pkgdown.yml b/_pkgdown.yml index 0d83f0f..54328ab 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,6 +1,7 @@ -url: ~ +url: https://seandavi.github.io/programets/ template: bootstrap: 5 bslib: bootswatch: materia pkgdown-nav-height: 100px + diff --git a/vignettes/googleanalytics.qmd b/vignettes/googleanalytics.qmd index 78dbc97..3b14c9f 100644 --- a/vignettes/googleanalytics.qmd +++ b/vignettes/googleanalytics.qmd @@ -21,19 +21,21 @@ The package provides functions to authenticate with your Google account, retriev # Getting started with `googleAnalyticsR` - ```{r} -## setup +#| label: setup library(googleAnalyticsR) library(programets) ``` -```{r eval=FALSE} -## authenticate +```{r} +#| eval: false +#| label: authenticate ga_auth(email = "seandavi@gmail.com") ``` -```{r echo=FALSE} +```{r} +#| echo: false +#| label: service_account json_file <- gargle::secret_decrypt_json( path = system.file( "secret", @@ -49,25 +51,21 @@ ga_auth(email = "seandavi@gmail.com") ``` ```{r} -## get your accounts +#| label: get-accounts account_list <- ga_account_list("ga4") -## account_list will have a column called "viewId" -account_list$viewId +## account_list will have a column called "propertyId" +account_list$propertyId ## View account_list and pick the one that you want to use ## In this case, we will use Bioconductor ga_id <- 388188354 - ``` The resulting `res` object will contain the data for the specified date range, metrics, and dimensions. You can view the first few rows of the data using the `head()` function. - - - ```{r} -library(googleAnalyticsR) +#| label: get-data library(lubridate) start_date <- Sys.Date() - 365 @@ -85,28 +83,27 @@ daily_user_country_data <- ga_data( ```{r} #| label: moving-average - library(ggplot2) library(zoo) library(dplyr) # Group by user type and country, then calculate rolling average -moving_avg_data <- daily_user_country_data %>% - arrange(date) %>% - group_by(newVsReturning, country) %>% +moving_avg_data <- daily_user_country_data |> + arrange(date) |> + group_by(newVsReturning, country) |> mutate( activeUsers_7day_avg = rollmean(activeUsers, k = 7, fill = NA, align = "right"), sessions_7day_avg = rollmean(sessions, k = 7, fill = NA, align = "right") - ) %>% + ) |> ungroup() # Let's see the results head(moving_avg_data) # Plot the moving average for active users -moving_avg_data %>% - group_by(date, newVsReturning) %>% - summarise(activeUsers_7day_avg = sum(activeUsers_7day_avg, na.rm = TRUE)) %>% +moving_avg_data |> + group_by(date, newVsReturning) |> + summarise(activeUsers_7day_avg = sum(activeUsers_7day_avg, na.rm = TRUE)) |> ggplot(aes(x = date, y = activeUsers_7day_avg, color = newVsReturning)) + geom_line() + labs(