get_name: Extract symbol names (tickers) from a vector of _character_...

Description Usage Arguments Details Value Examples

View source: R/rutils.R

Description

Extract symbol names (tickers) from a vector of character strings.

Usage

1
get_name(str_ing, sepa_rator = "[.]", field = 1)

Arguments

str_ing

A vector of character strings containing symbol names.

codesepa_rator

The name separator, i.e. the single character that separates the symbol name from the rest of the string (default is "[.]").

codefield

The position of the name in the string, i.e. the integer index of the field to be extracted (default is 1, i.e. the name is at the beginning of the string,)

Details

The function get_name() extracts the symbol names (tickers) from a vector of character strings. If the input is a vector of strings, then get_name() returns a vector of names.

The input string is assumed to be in the format "name.csv", with the name at the beginning of the string, but get_name() can also parse the name from other string formats as well. For example, it extracts the name "VTI" from the string "VTI.Close", or it extracts the name "XLU" from the string "XLU_2017_09_05.csv" (with sepa_rator="_").

JK: I really don't like sepa_rator

Value

A vector of character strings containing symbol names.

Examples

1
2
3
4
5
6
7
# Extract symbols "XLU" and"XLP" from file names
rutils::get_name(c("XLU.csv", "XLP.csv"))
# Extract symbols from file names
rutils::get_name("XLU_2017_09_05.csv", sep="_")
rutils::get_name("XLU 2017 09 05.csv", sep=" ")
# Extract fields "Open", "High", "Low", "Close" from column names
rutils::get_name(colnames(rutils::etf_env$VTI), field=2)

algoquant/rutils documentation built on Feb. 26, 2021, 1:30 a.m.