Skip to content

Commit

Permalink
fix: merging conflicts
Browse files Browse the repository at this point in the history
Merge branch 'main' of /~https://github.com/laresbernardo/lares

# Conflicts:
#	DESCRIPTION
  • Loading branch information
bl896211_gsk committed Feb 19, 2025
2 parents ecaa1dd + 8a4a840 commit 93d0cf5
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Suggests:
rmarkdown
URL: /~https://github.com/laresbernardo/lares, https://laresbernardo.github.io/lares/
BugReports: /~https://github.com/laresbernardo/lares/issues
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
License: AGPL-3
Encoding: UTF-8
LazyData: true
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export(num_abbr)
export(numericalonly)
export(ohe_commas)
export(ohse)
export(outlier_tukey)
export(outlier_turkey)
export(outlier_zscore)
export(outlier_zscore_plot)
Expand Down
12 changes: 8 additions & 4 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#' if the cache should be used to proceed or ignored; when writing, (interactive)
#' ask the user if the cache should be overwritten. Note that you can only ask for
#' one cache file at a time because vectors are concatenated.
#' @param overwrite Boolean. Set to overwrite existing cache file. When reading,
#' this parameter answers to ask prompt instead.
#' @param ... Additional parameters.
#' @return \code{cache_write}. No return value, called for side effects.
#' @examples
Expand All @@ -32,6 +34,7 @@ cache_write <- function(data,
base = "temp",
cache_dir = getOption("LARES_CACHE_DIR"),
ask = FALSE,
overwrite = NULL,
quiet = FALSE,
...) {
if (is.null(cache_dir)) {
Expand All @@ -51,11 +54,11 @@ cache_write <- function(data,
} else {
answer <- "use"
}
if (answer != "i") {
if (answer != "i" && isTRUE(overwrite)) {
saveRDS(data, file = file)
if (!quiet) message("> Cache saved succesfully: ", base)
} else {
if (!quiet) message("> Skipped cache for: ", base)
if (!quiet) message("> Skipped writing cache for: ", base)
return(invisible(NULL))
}
} else {
Expand All @@ -69,6 +72,7 @@ cache_write <- function(data,
cache_read <- function(base,
cache_dir = getOption("LARES_CACHE_DIR"),
ask = FALSE,
overwrite = TRUE,
quiet = FALSE,
...) {
base <- paste(base, collapse = ".")
Expand All @@ -78,13 +82,13 @@ cache_read <- function(base,
if (exists) {
file <- attr(exists, "filename")
base <- attr(exists, "base")
if (ask == TRUE) {
if (ask) {
message("> Cache found: ", base)
answer <- readline("Press ENTER to use cache or type [i] to ignore: ")
} else {
answer <- "use"
}
if (answer != "i") {
if (answer != "i" && isTRUE(overwrite)) {
data <- readRDS(file)
if (!quiet) message("> Cache loaded succesfully: ", base)
return(data)
Expand Down
5 changes: 4 additions & 1 deletion R/outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ outlier_zscore_plot <- function(df, var, group = NULL,
#' @param k Positive Numeric. K-multiplier.
#' @return Boolean vector detecting outliers.
#' @export
outlier_turkey <- function(x, k = 1.5) {
outlier_tukey <- function(x, k = 1.5) {
quar <- quantile(x, probs = c(0.25, 0.75), na.rm = TRUE)
iqr <- diff(quar)
!((quar[1] - k * iqr <= x) & (x <= quar[2] + k * iqr))
}
#' @rdname outlier_tukey
#' @export
outlier_turkey <- outlier_tukey
21 changes: 10 additions & 11 deletions R/stocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#'
#' @family Investment
#' @family Credentials
#' @inheritParams cache_write
#' @param file Character. Import an Excel file, local or from URL.
#' @param creds Character. Dropbox's credentials (see \code{get_creds()})
#' @param auto Boolean. Automatically use my local personal file? You might want
Expand Down Expand Up @@ -35,7 +36,8 @@ stocks_file <- function(file = NA,
sheets = c("Portafolio", "Fondos", "Transacciones"),
keep_old = TRUE,
cache = TRUE,
quiet = FALSE) {
quiet = FALSE,
...) {
cache_file <- c(as.character(Sys.Date()), "stocks_file")
if (cache_exists(cache_file) && cache) {
results <- cache_read(cache_file, quiet = quiet)
Expand All @@ -46,12 +48,15 @@ stocks_file <- function(file = NA,
as_tibble(read.xlsx(
file,
sheet = x,
skipEmptyRows = TRUE, detectDates = TRUE
skipEmptyRows = TRUE,
detectDates = TRUE
))
})
if (length(mylist) == 3) {
names(mylist) <- c("port", "cash", "trans")
mylist$trans$Date <- try(as.Date(mylist$trans$Date, origin = "1970-01-01"))
mylist$port$StartDate <- try(as.Date(mylist$port$StartDate, origin = "1889-12-31", ...))
mylist$trans$Date <- try(as.Date(mylist$trans$Date, origin = "1889-12-31", ...))
mylist$cash$Date <- try(as.Date(mylist$cash$Date, origin = "1889-12-31", ...))
if ("Value" %in% colnames(mylist$trans)) {
mylist$trans <- rename(mylist$trans, Each = .data$Value, Invested = .data$Amount)
}
Expand Down Expand Up @@ -96,7 +101,7 @@ stocks_file <- function(file = NA,
attr(results$cash, "type") <- "stocks_file_cash"
}
attr(results, "type") <- "stocks_file"
cache_write(results, cache_file, quiet = TRUE)
cache_write(results, cache_file, quiet = TRUE, ...)
return(results)
}

Expand Down Expand Up @@ -182,10 +187,7 @@ stocks_hist <- function(symbols = c("VTI", "META"),
cache = TRUE,
quiet = FALSE,
...) {
cache_file <- c(
as.character(Sys.Date()), "stocks_hist",
symbols, sum(as.integer(as.Date(from)), as.integer(as.Date(to)))
)
cache_file <- c(as.character(Sys.Date()), "stocks_hist")
if (cache_exists(cache_file) && cache) {
results <- cache_read(cache_file, quiet = quiet)
return(results)
Expand Down Expand Up @@ -1087,7 +1089,6 @@ etf_sector <- function(etf = "VTI", quiet = FALSE, cache = TRUE) {
if ("daily_stocks" %in% attr(etf, "type")) {
etf <- as.character(unique(etf$Symbol[etf$Date == max(etf$Date)]))
}

cache_file <- c(as.character(Sys.Date()), "etf_sector", etf)
if (cache_exists(cache_file) && cache) {
results <- cache_read(cache_file, quiet = quiet)
Expand Down Expand Up @@ -1156,9 +1157,7 @@ etf_sector <- function(etf = "VTI", quiet = FALSE, cache = TRUE) {
#' @rdname stocks_plots
splot_etf <- function(s, keep_all = FALSE, cache = TRUE, save = FALSE) {
check_attr(s, check = "daily_stocks")

if (!"Date" %in% colnames(s)) s$Date <- Sys.Date()

cache_file <- c(as.character(Sys.Date()), "splot_etf", s)
if (cache_exists(cache_file) && cache) {
etfs <- cache_read(cache_file, quiet = quiet)
Expand Down
5 changes: 5 additions & 0 deletions man/cache_write.Rd

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

5 changes: 4 additions & 1 deletion man/outlier_turkey.Rd → man/outlier_tukey.Rd

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

2 changes: 1 addition & 1 deletion man/outlier_zscore.Rd

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

2 changes: 1 addition & 1 deletion man/outlier_zscore_plot.Rd

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

7 changes: 4 additions & 3 deletions man/stocks_report.Rd

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

2 changes: 1 addition & 1 deletion man/winsorize.Rd

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

0 comments on commit 93d0cf5

Please sign in to comment.