Skip to content

Commit aa4a75c

Browse files
committed
Add argument to set column name
This allows the user to specify a custom column name, instead of the default being hard-coded to the symbol + .div or .spl. Fixes #369.
1 parent f3b5844 commit aa4a75c

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

R/getDividends.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
`getDividends` <-
22
function(Symbol,from='1970-01-01',to=Sys.Date(),env=parent.frame(),src='yahoo',
33
auto.assign=FALSE,auto.update=FALSE,verbose=FALSE,split.adjust=TRUE,...,
4+
colname=NULL,
45
curl.options=list()) {
56

67
tmp.symbol <- Symbol
@@ -59,7 +60,11 @@ function(Symbol,from='1970-01-01',to=Sys.Date(),env=parent.frame(),src='yahoo',
5960
}
6061

6162
fr <- divs
62-
colnames(fr) <- paste(Symbol.name,'div',sep='.')
63+
if(is.null(colname)) {
64+
colnames(fr) <- paste(Symbol.name,'div',sep='.')
65+
} else {
66+
colnames(fr) <- colname
67+
}
6368
} else {
6469
fr <- xts(numeric(0), .Date(integer(0)))
6570
}

R/getSplits.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
`getSplits` <-
22
function(Symbol,from='1970-01-01',to=Sys.Date(),env=parent.frame(),src='yahoo',
3-
auto.assign=FALSE,auto.update=FALSE,verbose=FALSE,...,
3+
auto.assign=FALSE,auto.update=FALSE,verbose=FALSE,...,colname=NULL,
44
curl.options=list()) {
55

66
# Function written by Joshua Ulrich, using
@@ -47,7 +47,11 @@ function(Symbol,from='1970-01-01',to=Sys.Date(),env=parent.frame(),src='yahoo',
4747
xts(ratio, as.Date(.POSIXct(x$date, "UTC")))
4848
}
4949
fr <- 1 / do.call(rbind, lapply(split.events, to.xts))
50-
colnames(fr) <- paste(Symbol.name,'spl',sep='.')
50+
if(is.null(colname)) {
51+
colnames(fr) <- paste(Symbol.name,'spl',sep='.')
52+
} else {
53+
colnames(fr) <- colname
54+
}
5155
} else {
5256
fr <- xts(numeric(0), .Date(integer(0)))
5357
}

man/getDividends.Rd

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ getDividends(Symbol,
1616
verbose = FALSE,
1717
split.adjust = TRUE,
1818
...,
19+
colname=NULL,
1920
curl.options = list())
2021
}
2122
%- maybe also 'usage' for other objects documented here.
@@ -31,6 +32,7 @@ getDividends(Symbol,
3132
\item{split.adjust}{ adjust dividends for splits (\code{TRUE} by default
3233
because that's what Yahoo returns)}
3334
\item{\dots}{ currently unused }
35+
\item{colname}{ name for the column of data }
3436
\item{curl.options}{ options passed to \code{curl::curl} }
3537
}
3638
\details{
@@ -53,11 +55,7 @@ as an \code{xts} object.
5355
}
5456
\references{ Yahoo! Finance: \url{https://finance.yahoo.com}}
5557
\author{ Jeffrey A. Ryan }
56-
\note{
57-
This function is very preliminary - and will most likely
58-
change significantly in the future.
59-
}
60-
\seealso{ \code{\link{getSymbols}} }
58+
\seealso{ \code{\link{getSymbols}}, \code{\link{getSplits}} }
6159
\examples{
6260
\dontrun{
6361
getSymbols("MSFT")

man/getSplits.Rd

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ getSplits(Symbol,
1515
auto.update = FALSE,
1616
verbose = FALSE,
1717
...,
18+
colname=NULL,
1819
curl.options = list())
1920
}
2021
%- maybe also 'usage' for other objects documented here.
@@ -28,6 +29,7 @@ getSplits(Symbol,
2829
\item{auto.update}{ automatically add split to data object }
2930
\item{verbose}{ display status of retrieval }
3031
\item{\dots}{ currently unused }
32+
\item{colname}{ name for the column of data }
3133
\item{curl.options}{ options passed to \code{curl::curl} }
3234
}
3335
\details{
@@ -50,11 +52,7 @@ as an \code{xts} object. \code{NA} is returned if there
5052
is no split data.
5153
}
5254
\references{ Yahoo! Finance: \url{https://finance.yahoo.com}}
53-
\author{ Josh Ulrich }
54-
\note{
55-
This function is very preliminary - and will most likely
56-
change significantly in the future.
57-
}
55+
\author{ Joshua Ulrich }
5856
\seealso{ \code{\link{getSymbols}}, \code{\link{getDividends}} }
5957
\examples{
6058
\dontrun{

0 commit comments

Comments
 (0)