Skip to content

Commit bf92f8a

Browse files
committed
add package cache for code_get function
1 parent 945663a commit bf92f8a

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ importFrom(rvest,html_attr)
2222
importFrom(rvest,html_nodes)
2323
importFrom(rvest,html_text)
2424
importFrom(stringr,str_sub)
25-
importFrom(tibble,as.tibble)
2625
importFrom(tibble,as_tibble)
26+
importFrom(tibble,tibble)

R/code_get.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
#'
33
#' Get code for korea finance market
44
#'
5-
#' @return a [tibble][tibble::tibble-package]
5+
#' @param fresh get code on internet. Default is FALSE.
6+
#' @return a [tibble][tibble::tibble-package] with market, name, code column.
67
#' @export
78
#' @importFrom purrr map_dfr
8-
code_get <- function() {
9+
code_get <- function(fresh = FALSE) {
10+
if (!fresh) {
11+
return(code)
12+
}
913
c("stockMkt", "kosdaqMkt", "konexMkt") %>%
1014
purrr::map_dfr( ~ get_corps_info(.x)) %>%
1115
return()
@@ -45,7 +49,7 @@ get_corps_info <- function(market) {
4549
stringr::str_sub(22, 26) -> code
4650

4751
return(
48-
tibble::tibble(
52+
tibble(
4953
market = market_name, name, code
5054
)
5155
)

R/sysdata.rda

19.2 KB
Binary file not shown.

R/tqk-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"_PACKAGE"
33

44
## usethis namespace: start
5+
#' @importFrom tibble tibble
56
## usethis namespace: end
67
NULL

R/tqk_get.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#' @export
1010
#' @importFrom curl curl_fetch_memory
1111
#' @importFrom jsonlite fromJSON
12-
#' @importFrom tibble as.tibble
1312
#' @importFrom httr add_headers user_agent GET content
1413
#' @importFrom purrr transpose
1514
#' @importFrom tibble as_tibble
@@ -52,7 +51,7 @@ tqk_get <-
5251

5352
dl <- lapply(cont, function(x)
5453
jsonlite::fromJSON(x)$list)
55-
df <- tibble::as.tibble(do.call(rbind, dl))
54+
df <- tibble::as_tibble(do.call(rbind, dl))
5655
if (tqform) {
5756
df <-
5857
df[, c("tradeDt",

data-raw/code.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## code to prepare `code` dataset goes here
2+
3+
library(tqk)
4+
5+
code <- code_get(fresh = TRUE)
6+
7+
usethis::use_data(code, overwrite = TRUE, internal = TRUE)

man/code_get.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)