View source: R/saveInstruments.R
| saveInstruments | R Documentation |
Saves (loads) the .instrument environment to (from) disk.
saveInstruments(file_name = "MyInstruments", dir = "", compress = "gzip")
loadInstruments(file_name = "MyInstruments", dir = "")
reloadInstruments(file_name = "MyInstruments", dir = "")
file_name |
name of file. e.g. “MyInstruments.RData”.
As an experimental feature, a |
dir |
Directory of file (defaults to current working directory. ie. "") |
compress |
argument passed to |
After you have defined some instruments, you can use saveInstruments
to save the entire .instrument environment to disk.
loadInstruments will read a file that contains instruments and add
those instrument definitions to your .instrument environment.
reloadInstruments will remove all instruments in the current
.instrument environment before loading instruments from disk.
The file_name should have a file extension of “RData”,
“rda”, “R”, or “txt”. If the file_name does not
end with one of those, “.RData” will be appended to the
file_name
If the file extension is “R” or “txt”, saveInstruments
will create a text file of R code that can be sourced to
load instruments back into the .instrument environment.
Called for side-effect
Garrett See
save, load load.instrument define_stocks, define_futures, define_options (option_series.yahoo)
backup_file <- tempfile(fileext = ".RData")
output_dir <- tempfile("fi-save-test-")
dir.create(output_dir)
saveInstruments(backup_file)
tryCatch(
{
rm_instruments(keep.currencies = FALSE)
currency("USD")
stock("SPY", currency = "USD")
saveInstruments(
"test-instruments.R",
dir = output_dir
)
rm_instruments(keep.currencies = FALSE)
source(
file.path(output_dir, "test-instruments.R")
)
stopifnot(is.instrument.name("SPY"))
stopifnot(getInstrument("SPY")$currency == "USD")
},
finally = {
reloadInstruments(backup_file)
unlink(backup_file)
unlink(output_dir, recursive = TRUE)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.