Skip to content

Commit

Permalink
Fix and render the HTML version
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvartan committed Nov 27, 2024
1 parent c2dd103 commit 5a74c5a
Show file tree
Hide file tree
Showing 406 changed files with 49,961 additions and 5,697 deletions.
23 changes: 12 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# See <https://git-scm.com/docs/gitignore>.

_freeze/
_print/
_slides/
_web/
_targets/
_temp/
_ssh/
.auth/
.quarto/
/_freeze/
/_print/
/_slides/
/_web/
/_targets/
/_temp/
/_ssh/
/.auth/
/.quarto/
/index_cache/
/site_libs/

.Rapp.history
.RData
.Renviron
.Rhistory
.Rproj.user
.Ruserdata

/.quarto/
3 changes: 3 additions & 0 deletions R/_dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
# source(here::here("R", "_pre-render-html.R"))
# source(here::here("R", "_pre-render-revealjs.R"))
#
# --cache
# --no-cache
# --cache-refresh
# quarto render
# quarto render --profile gfm
# quarto render --profile pdf
Expand Down
2 changes: 1 addition & 1 deletion R/_post-render-end.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ output_docs_new_files <-
output_docs_new_dirs <- list.dirs(
path = get(paste0("output_dir_", env_vars$format)),
full.names = FALSE
)[-1] %>%
)[-1] %>%
here::here(get(paste0("output_docs_", env_vars$format)), .)

for (i in output_docs_old_files) {
Expand Down
7 changes: 4 additions & 3 deletions R/_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(downlit)
# library(extrafont)
# library(here)
# library(knitr)
library(lubridate)
library(magrittr)
library(ggplot2)
library(rlang)
Expand All @@ -16,7 +17,7 @@ library(xml2)

# Load functions -----

source(here::here("R/utils.R"))
source(here::here("R", "utils.R"))

# Set general options -----

Expand Down Expand Up @@ -75,7 +76,7 @@ ggplot2::theme_set(
ggplot2::theme_bw(
base_size = base_size,
base_family = env_vars$sansfont,
base_line_size = base_size / 22, # `ggplot2::theme_gray` default
base_rect_size = base_size / 22 # `ggplot2::theme_gray` default
base_line_size = base_size / 22,
base_rect_size = base_size / 22
)
)
62 changes: 1 addition & 61 deletions R/add_solar_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ add_solar_data <- function(
data |>
add_ghi(inpe_data) |>
add_equinox_and_solstice(time_and_date_data) |>
add_sun_time() |>
nest_solar_vars()
add_sun_time()
}

# library(dplyr)
Expand Down Expand Up @@ -243,62 +242,3 @@ add_sun_time <- function(data) {
) |>
dplyr::relocate(dplyr::matches("^december_"), .before = height)
}

# library(dplyr)
# library(prettycheck) # github.com/danielvartan/prettycheck
# library(purrr)
# library(tidyr)

nest_solar_vars <- function(data) {
prettycheck:::assert_tibble(data)

data |>
tidyr::nest(
ghi = c(ghi_month, ghi_annual),
march_equinox = c(
march_equinox, march_equinox_sunrise, march_equinox_sunset,
march_equinox_daylight
),
june_solstice = c(
june_solstice, june_solstice_sunrise, june_solstice_sunset,
june_solstice_daylight
),
september_equinox = c(
september_equinox, september_equinox_sunrise,
september_equinox_sunset, september_equinox_daylight
),
december_solstice = c(
december_solstice, december_solstice_sunrise,
december_solstice_sunset, december_solstice_daylight
)
) |>
dplyr::mutate(
ghi = ghi |>
purrr::map(
.f = ~ .x |>
dplyr::rename_with(.fn = ~ c("month", "annual"))
)
) |>
dplyr::mutate(
dplyr::across(
.cols = dplyr::all_of(
c(
"march_equinox", "june_solstice", "september_equinox",
"december_solstice"
)
),
.fns = ~ .x |>
purrr::map(
.f = ~ .x |>
dplyr::rename_with(
.fn = ~ c("moment", "sunrise", "sunset", "daylight")
)
)
)
) |>
dplyr::relocate(
ghi, march_equinox, june_solstice, september_equinox,
december_solstice,
.after = longitude
)
}
6 changes: 3 additions & 3 deletions R/categorize_msf_sc.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# library(dplyr)
# library(here)
# library(lubridate)
library(lubridate)
# library(prettycheck) # github.com/danielvartan/prettycheck

source(here::here("R/get_chronotype_cutoffs.R"))
source(here::here("R/utils.R"))
source(here::here("R", "get_chronotype_cutoffs.R"))
source(here::here("R", "utils.R"))

categorize_msf_sc <- function(x) {
prettycheck:::assert_hms(x)
Expand Down
159 changes: 138 additions & 21 deletions R/lock_and_store_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,48 @@ lock_and_store_data <- function(
upload_to_osf = FALSE,
name_pattern = deparse(substitute(data))
) {
prettycheck:::assert_internet()
prettycheck:::assert_tibble(data)
prettycheck:::assert_string(osf_pat, n.chars = 70)
lockr:::assert_public_key(public_key)
prettycheck:::assert_flag(upload_to_osf)
prettycheck:::assert_string(name_pattern)

osfr::osf_auth(osf_pat) |> rutils::shush()
osf_id <- "https://osf.io/cbqsa"
test <- try(osfr::osf_retrieve_node(osf_id), silent = TRUE)
data |>
lock_data(
public_key = public_key,
name_pattern = name_pattern
) |>
store_data(
osf_pat = osf_pat,
upload_to_osf = upload_to_osf
)
}

if (inherits(test, "try-error")) {
cli::cli_abort(paste0(
"The {.strong {cli::col_red('OSF PAT')}} provided is invalid. ",
"Please, check the access token and try again."
))
}
# library(cli)
# library(dplyr)
# library(hardhat)
# library(here)
# library(lockr) # github.com/danielvartan/lockr
# library(lubridate)
# library(lubritime)
# library(prettycheck) # github.com/danielvartan/prettycheck
# library(tidyr)

source(here::here("R", "save_and_lock.R"))

lock_data <- function(
data,
public_key = here::here("_ssh", "id_rsa.pub"),
name_pattern = deparse(substitute(data))
) {
prettycheck:::assert_tibble(data)
lockr:::assert_public_key(public_key)
prettycheck:::assert_string(name_pattern)

cli::cli_progress_step("Locking and saving data.")

file_name_pattern <- name_pattern

rds_file <-
data |>
save_and_lock(
file = file.path(tempdir(), paste0(file_name_pattern, ".rds")),
type = "rds",
public_key = public_key,
compress = "bz2"
)

csv_file <-
data |>
tidyr::unnest(
Expand Down Expand Up @@ -80,18 +92,123 @@ lock_and_store_data <- function(
public_key = public_key
)

if (any(c("ghi_month", march_equinox) %in% names(data))) {
data <- nest_solar_vars(data)
}

rds_file <-
data |>
save_and_lock(
file = file.path(tempdir(), paste0(file_name_pattern, ".rds")),
type = "rds",
public_key = public_key,
compress = "bz2"
)

# file.size(rds_file) / 1e+6
# file.size(csv_file) / 1e+6

c(rds_file, csv_file)
}

# library(cli)
# library(osfr)
# library(prettycheck) # github.com/danielvartan/prettycheck
# library(rutils) # github.com/danielvartan/rutils

store_data <- function(
file,
osf_pat = Sys.getenv("OSF_PAT"),
upload_to_osf = TRUE,
) {
prettycheck:::assert_flag(upload_to_osf)

if (isTRUE(upload_to_osf)) {
prettycheck:::assert_internet()
prettycheck:::assert_character(file)
for (i in file) prettycheck:::assert_file_exists(i)
prettycheck:::assert_string(osf_pat, n.chars = 70)

osfr::osf_auth(osf_pat) |> rutils::shush()
osf_id <- "https://osf.io/cbqsa"
test <- try(osfr::osf_retrieve_node(osf_id), silent = TRUE)

if (inherits(test, "try-error")) {
cli::cli_abort(paste0(
"The {.strong {cli::col_red('OSF PAT')}} provided is invalid. ",
"Please, check the access token and try again."
))
}

cli::cli_progress_step("Uploading data to OSF.")

osfr::osf_upload(
x = osfr::osf_retrieve_node(osf_id),
path = c(rds_file, csv_file),
path = file,
conflicts = "overwrite"
)
}

invisible(data)
invisible()
}

# library(dplyr)
# library(prettycheck) # github.com/danielvartan/prettycheck
# library(purrr)
# library(tidyr)

nest_solar_vars <- function(data) {
prettycheck:::assert_tibble(data)

cli::cli_progress_step("Nesting solar variables.")

data |>
tidyr::nest(
ghi = c(ghi_month, ghi_annual),
march_equinox = c(
march_equinox, march_equinox_sunrise, march_equinox_sunset,
march_equinox_daylight
),
june_solstice = c(
june_solstice, june_solstice_sunrise, june_solstice_sunset,
june_solstice_daylight
),
september_equinox = c(
september_equinox, september_equinox_sunrise,
september_equinox_sunset, september_equinox_daylight
),
december_solstice = c(
december_solstice, december_solstice_sunrise,
december_solstice_sunset, december_solstice_daylight
)
) |>
dplyr::mutate(
ghi = ghi |>
purrr::map(
.f = ~ .x |>
dplyr::rename_with(.fn = ~ c("month", "annual"))
)
) |>
dplyr::mutate(
dplyr::across(
.cols = dplyr::all_of(
c(
"march_equinox", "june_solstice", "september_equinox",
"december_solstice"
)
),
.fns = ~ .x |>
purrr::map(
.f = ~ .x |>
dplyr::rename_with(
.fn = ~ c("moment", "sunrise", "sunset", "daylight")
)
)
)
) |>
dplyr::relocate(
ghi, march_equinox, june_solstice, september_equinox,
december_solstice,
.after = longitude
)
}
6 changes: 4 additions & 2 deletions R/panel_tabset_coef_dfbetas.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ panel_tabset_coef_dfbetas <- function(
source = rep("Created by the author.", length(coef)),
heading = "###",
fit_engine_name = "fit_engine",
suffix = ""
suffix = "",
root = ".."
) {
prettycheck:::assert_class(fit_engine, "lm")

Expand All @@ -36,6 +37,7 @@ panel_tabset_coef_dfbetas <- function(
prettycheck:::assert_string(heading, pattern = "^#*")
prettycheck:::assert_string(fit_engine_name)
prettycheck:::assert_string(suffix)
prettycheck:::assert_string(root)

if (!file.exists(here::here("qmd"))) dir.create(here::here("qmd"))

Expand Down Expand Up @@ -117,7 +119,7 @@ panel_tabset_coef_dfbetas <- function(
readr::write_lines(file)

include_string <- glue::glue(
"{{{{< include {to_relative_path(file)} >}}}}"
"{{{{< include {to_relative_path(file, root)} >}}}}"
)

cli::cli_alert_info(glue:::glue(
Expand Down
Loading

0 comments on commit 5a74c5a

Please sign in to comment.