View source: R/CompareInstrumentFiles.R
| CompareInstrumentFiles | R Documentation |
Compare the .instrument environments of two files
CompareInstrumentFiles(file1, file2, ...)
file1 |
A file containing an instrument environment |
file2 |
Another file containing an instrument environment. If not
provided, |
... |
Arguments to pass to |
This will load two instrument files (created by
saveInstruments) and find the differences between them. In
addition to returning a list of difference that are found, it will produce
messages indicating the number of instruments that were added, the number of
instruments that were removed, and the number of instruments that are
different.
A list that contains the names of all instruments that were added,
the names of all instruments that were removed, and the changes to all
instruments that were updated (per all.equal.instrument).
Garrett See
saveInstruments, all.equal.instrument
example_dir <- tempfile("fi-compare-")
dir.create(example_dir)
backup_name <- "backup.RData"
file1_name <- "instruments1.RData"
file2_name <- "instruments2.RData"
backup_path <- file.path(example_dir, backup_name)
file1_path <- file.path(example_dir, file1_name)
file2_path <- file.path(example_dir, file2_name)
saveInstruments(backup_name, dir = example_dir)
tryCatch(
{
stopifnot(file.exists(backup_path))
rm_instruments(keep.currencies = FALSE)
currency("USD")
stock(c("SPY", "DIA", "GLD"), currency = "USD")
saveInstruments(file1_name, dir = example_dir)
stopifnot(file.exists(file1_path))
rm_stocks("GLD")
stock("QQQ", currency = "USD")
instrument_attr(
"SPY",
"description",
"S&P 500 ETF"
)
saveInstruments(file2_name, dir = example_dir)
stopifnot(file.exists(file2_path))
CompareInstrumentFiles(file1_path, file2_path)
},
finally = {
if (file.exists(backup_path)) {
reloadInstruments(backup_name, dir = example_dir)
}
unlink(example_dir, recursive = TRUE)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.