Learn R Programming

FinancialInstrument (version 1.4.1)

saveSymbols.days: Save data to disk

Description

Save data to disk the way that getSymbols.FI expects it to be saved.

Usage

saveSymbols.days(Symbols, base_dir = "", extension = "rda", env = .GlobalEnv)

saveSymbols.common(Symbols, base_dir = "", extension = "rda", env = .GlobalEnv)

Value

called for side-effect.

Arguments

Symbols

character vector of names of objects to be saved

base_dir

character. directory in which to store data.

extension

file extension (“rda”)

env

environment that holds the data to be saved (.GlobalEnv by default)

Details

If they do not already exist, subdirectories will be created for each of the Symbols. saveSymbols.common will save a single ‘rda’ file for each of the Symbols in that symbol's subdirectory. saveSymbols.days will split the data up into days and save a separate ‘rda’ file for each day in that symbol's subdirectory.

See Also

getSymbols.FI

Examples

Run this code
example_dir <- tempfile("fi-symbol-data-")
dir.create(example_dir)

example_env <- new.env()

example_env$SPY <- xts::xts(
  matrix(
    1:8,
    ncol = 2L,
    dimnames = list(
      NULL,
      c("Close", "Volume")
    )
  ),
  order.by = as.Date("2020-01-01") + 0:3
)

tryCatch(
  {
    saveSymbols.common(
      "SPY",
      base_dir = example_dir,
      env = example_env
    )

    list.files(
      example_dir,
      recursive = TRUE
    )
  },
  finally = {
    unlink(example_dir, recursive = TRUE)
  }
)

Run the code above in your browser using DataLab