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

View source: R/rutils.R

get_nameR Documentation

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

Description

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

Usage

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

Arguments

str_ing

A vector of character strings containing symbol names.

sep

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

field

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 "XLU2017_09_05.csv" (with sep="_").

Value

A vector of character strings containing symbol names.

Examples

# Extract symbols "XLU" and"XLP" from file names
rutils::get_name(c("XLU.csv", "XLP.csv"))
# Extract symbols from file names
rutils::get_name("XLU2017_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(c("VTI.Open", "VTI.High", "VTI.Low", "VTI.Close"), field=2)

algoquant/rutils documentation built on April 18, 2024, 12:05 a.m.