View source: R/data_adapters.R
| csv_adapter | R Documentation |
Reads stock price data from CSV files with flexible column naming. Automatically standardizes to library format.
csv_adapter(
file_path,
date_col = "Date",
symbol_col = "Symbol",
price_col = "Price",
frequency = "daily",
symbol_order = NULL
)
file_path |
Path to CSV file |
date_col |
Name of date column (default: "date") |
symbol_col |
Name of symbol column (default: "symbol") |
price_col |
Name of price column (default: "close") |
frequency |
Target frequency: "daily" or "weekly" (default: "daily") |
symbol_order |
Optional vector to order symbols |
Data.table with Date column and price columns
# Create a temporary tidy CSV from included weekly sample data (offline, fast)
data("sample_prices_weekly")
PW <- as.data.frame(sample_prices_weekly)
syms <- setdiff(names(PW), "Date")[1:2]
stk <- stack(PW[1:10, syms])
tidy <- data.frame(
Date = rep(PW$Date[1:10], times = length(syms)),
Symbol = stk$ind,
Price = stk$values
)
tmp <- tempfile(fileext = ".csv")
write.csv(tidy, tmp, row.names = FALSE)
prices <- csv_adapter(tmp)
head(prices)
unlink(tmp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.