Sunday, June 14, 2015

[2] Sourcing Libraries

Create the following r source file on a certain directory.

hello.r
print("Hello")


source()
Show files / directories on the current directory.

sample code(s)
# specify the path to the .r file
fileName <- "H:/Quantitative Research/R/hello.r"

# load and run the code from the file
source(fileName)
[1] "Hello"

library()
  • When you want to load the newly installed packages and use them in the new workspace, then use library().
  • Create the following setup.r file and run it.
setup.r
# setup libraries

# xts: a timeseries package
library(xts)

library(TTR)

# quantmod: extended graphing functionality; works well with xts
library(quantmod)

library(PerformanceAnalytics)
library(zoo)

# ========== Optimization ==========
library(quadprog)
library(timeDate)
library(timeSeries)
library(fBasics)
library(fAssets)
library(fMultivar)
library(robustbase)
library(DEoptimR)
library(ecodist)
library(mvnormtest)
library(energy)
library(sn)
library(mnormt)
library(numDeriv)
library(fCopulae)
library(Rglpk)
library(slam)
library(Rsymphony)
library(Rsolnp)
library(truncnorm)
library(kernlab)
library(rneos)
library(XML)
library(RCurl)
library(bitops)
library(fPortfolio)



library(stockPortfolio)
library(ggplot2)
library(reshape2)
library(digest)
library(gtable)
library(plyr)
library(Rcpp)
library(proto)
library(stringr)
library(stringi)
library(magrittr)
library(scales)
library(munsell)
library(colorspace)
library(labeling)

sample code(s)
# There could be an error saying "'PerformanceAnalytics' is built prior to R 3.0.0" or something, but please ignore it.

setupFile <- "H:/Quantitative Research/R/setup.r"
source(setupFile)


No comments:

Post a Comment