diff --git a/DESCRIPTION b/DESCRIPTION
index c388b0a..d1c996e 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: yfR
Title: Downloads and Organizes Financial Data from Yahoo Finance
-Version: 1.1.0
+Version: 1.1.1
Authors@R: c(person("Marcelo", "Perlin", email = "marceloperlin@gmail.com", role = c("aut", "cre")),
person("Nic", "Crane", role = "rev",
comment = "Nic reviewed the package (v. 0.0.5) for
@@ -41,7 +41,7 @@ Imports:
jsonlite
License: MIT + file LICENSE
LazyData: true
-RoxygenNote: 7.2.3
+RoxygenNote: 7.3.1
Suggests:
knitr,
rmarkdown,
diff --git a/NEWS.md b/NEWS.md
index df39ceb..cbd68d7 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,7 @@
+## Version 1.1.1 (2024-06-24) -- minor
+
+- new function check_internet() that will check for an active internet connection every R session. It will not repeat the test once it is passed.
+
## Version 1.1.0 (2023-01-30) -- major version
- new function yf_live_prices() (see this [pr](https://github.com/ropensci/yfR/pull/24))
diff --git a/R/yf_get.R b/R/yf_get.R
index cf47239..7bc0866 100644
--- a/R/yf_get.R
+++ b/R/yf_get.R
@@ -122,9 +122,7 @@ yf_get <- function(tickers,
be_quiet = FALSE) {
# check for internet
- if (!pingr::is_online()) {
- stop("Can't find an active internet connection...")
- }
+ check_internet()
# check cache folder
if ((do_cache) & (!dir.exists(cache_folder))) dir.create(cache_folder,
@@ -197,14 +195,14 @@ yf_get <- function(tickers,
# disable dplyr group message and respect user choice
# will be null if options is not set
- default_dplyr_summ <- options("dplyr.summarise.inform")[[1]]
+ default_dplyr_sum <- options("dplyr.summarise.inform")[[1]]
# disable and enable at end with on exit
options(dplyr.summarise.inform = FALSE)
on.exit({
- if (is.logical(default_dplyr_summ)) {
- options(dplyr.summarise.inform = default_dplyr_summ)
+ if (is.logical(default_dplyr_sum)) {
+ options(dplyr.summarise.inform = default_dplyr_sum)
}
})
diff --git a/R/yf_utils.R b/R/yf_utils.R
index 103b819..edf2b2e 100644
--- a/R/yf_utils.R
+++ b/R/yf_utils.R
@@ -162,3 +162,34 @@ substitute_tickers <- function(df_index) {
return(df_index)
}
+
+
+#' Tests for an internet connection
+#'
+#' Tests for internet connect in every R session. If already tested, just skip it and saves time.
+#'
+#' @noRd
+check_internet <- function() {
+ f_flag <- paste0(
+ tempdir(), "/",
+ "yf-flag-internet-ok"
+ )
+
+ if (file.exists(f_flag)) {
+
+ flag <- TRUE
+
+ } else {
+
+ flag <- pingr::is_online()
+
+ if (!flag) {
+ stop("Can't find an active internet connection...")
+ } else {
+ readr::write_lines("internet ok", f_flag)
+ }
+
+ }
+
+ return(flag)
+}
diff --git a/README.md b/README.md
index a15b5d4..eaf3c1b 100644
--- a/README.md
+++ b/README.md
@@ -77,8 +77,11 @@ The easiest way to find the tickers of a company stock is to search for
it in [Yahoo Finance’s](https://finance.yahoo.com/) website. At the top
page you’ll find a search bar:
-![YF
-Search](/inst/figures/search-yf.png?raw=true "Example of search in YF")
+
A company can have many different stocks traded at different markets
(see picture above). As the example shows, Petrobras is traded at NYQ
@@ -157,35 +160,37 @@ df_yf <- yf_get(tickers = my_ticker,
first_date = first_date,
last_date = last_date)
#>
-#> ── Running yfR for 1 stocks | 2023-01-17 --> 2023-02-16 (30 days) ──
+#> ── Running yfR for 1 stocks | 2024-05-25 --> 2024-06-24 (30 days) ──
#>
#> ℹ Downloading data for benchmark ticker ^GSPC
#> ℹ (1/1) Fetching data for META
#> ! - not cached
#> ✔ - cache saved successfully
-#> ✔ - got 22 valid rows (2023-01-17 --> 2023-02-15)
+#> ✔ - got 18 valid rows (2024-05-28 --> 2024-06-21)
#> ✔ - got 100% of valid prices -- Time for some tea?
#> ℹ Binding price data
#>
#> ── Diagnostics ─────────────────────────────────────────────────────────────────
-#> ✔ Returned dataframe with 22 rows -- Youre doing good!
-#> ℹ Using 6.3 kB at /tmp/RtmpvCnCwr/yf_cache for 2 cache files
+#> ✔ Returned dataframe with 18 rows -- You got it msperlin!
+#> ℹ Using 5.5 kB at /tmp/Rtmp8A98vn/yf_cache for 2 cache files
#> ℹ Out of 1 requested tickers, you got 1 (100%)
+```
+
+``` r
# output is a tibble with data
head(df_yf)
#> # A tibble: 6 × 11
-#> ticker ref_date price_open price_h…¹ price…² price…³ volume price…⁴ ret_ad…⁵
-#>
-#> 1 META 2023-01-17 136. 137. 134. 135. 2.11e7 135. NA
-#> 2 META 2023-01-18 136. 137. 133. 133. 2.02e7 133. -1.73e-2
-#> 3 META 2023-01-19 132. 137. 132. 136. 2.86e7 136. 2.35e-2
-#> 4 META 2023-01-20 136. 140. 135. 139. 2.86e7 139. 2.37e-2
-#> 5 META 2023-01-23 139. 144. 139. 143. 2.75e7 143. 2.80e-2
-#> 6 META 2023-01-24 142. 145 141. 143. 2.20e7 143. -9.07e-4
-#> # … with 2 more variables: ret_closing_prices ,
-#> # cumret_adjusted_prices , and abbreviated variable names ¹price_high,
-#> # ²price_low, ³price_close, ⁴price_adjusted, ⁵ret_adjusted_prices
+#> ticker ref_date price_open price_high price_low price_close volume
+#>
+#> 1 META 2024-05-28 477. 481. 475. 480. 10175800
+#> 2 META 2024-05-29 475. 480. 474. 474. 9226200
+#> 3 META 2024-05-30 472. 472. 465. 467. 10735200
+#> 4 META 2024-05-31 466. 469. 454. 467. 16919800
+#> 5 META 2024-06-03 471. 480. 468. 477. 11279400
+#> 6 META 2024-06-04 477 479. 473. 477. 7088700
+#> # ℹ 4 more variables: price_adjusted , ret_adjusted_prices ,
+#> # ret_closing_prices , cumret_adjusted_prices
```
# Acknowledgements
diff --git a/inst/WORDLIST b/inst/WORDLIST
index 6be2685..e647c67 100644
--- a/inst/WORDLIST
+++ b/inst/WORDLIST
@@ -2,12 +2,15 @@ Acknowledgements
BUE
BatchGetSymbols
Buenos
+CMD
Codecov
+DJI
EOD
Economática
FB
FTSE
GSPC
+Henrique
IBOV
NYQ
PETR
@@ -18,39 +21,37 @@ Reais
SAO
Sao
SimFin
+TSLA
YF
YYYY
api
arit
+cachefolder
cumret
dir
+dontrun
+donttest
furrr
futureverse
+github
https
+json
magrittr
md
mkt
openminded
+pingr
pre
quantmod
rOpenSci
rcmdcheck
rds
readme
+repo
ret
+ropensci
+roxygen
tempdir
tibble
-yf
-cachefolder
-github
-repo
-ropensci
-dontrun
-donttest
-TSLA
-pingr
tidyselect
-DJI
-json
-roxygen
-Henrique
+yf
diff --git a/inst/extdata/fallback-indices/DOW.rds b/inst/extdata/fallback-indices/DOW.rds
index 5cfaf3a..74d9708 100644
Binary files a/inst/extdata/fallback-indices/DOW.rds and b/inst/extdata/fallback-indices/DOW.rds differ
diff --git a/inst/extdata/fallback-indices/FTSE.rds b/inst/extdata/fallback-indices/FTSE.rds
index 863e617..b4a2d04 100644
Binary files a/inst/extdata/fallback-indices/FTSE.rds and b/inst/extdata/fallback-indices/FTSE.rds differ
diff --git a/inst/extdata/fallback-indices/IBOV.rds b/inst/extdata/fallback-indices/IBOV.rds
index 769851a..0d7dd36 100644
Binary files a/inst/extdata/fallback-indices/IBOV.rds and b/inst/extdata/fallback-indices/IBOV.rds differ
diff --git a/inst/extdata/fallback-indices/SP500.rds b/inst/extdata/fallback-indices/SP500.rds
index e846079..1134386 100644
Binary files a/inst/extdata/fallback-indices/SP500.rds and b/inst/extdata/fallback-indices/SP500.rds differ
diff --git a/inst/extdata/fallback-indices/testthat-collection.rds b/inst/extdata/fallback-indices/testthat-collection.rds
index 5233321..fae98d5 100644
Binary files a/inst/extdata/fallback-indices/testthat-collection.rds and b/inst/extdata/fallback-indices/testthat-collection.rds differ