rquantmod

Error: 'getXTS' is not an exported object from 'namespace:xts' in R


I am using APPL stock data from Yahoo. The code was running fine earlier, but it is not working now. I have tried to reload the R session and restart the machine, but it won't work. Need help!

Code:

# Loading all the required Libraries:
library(quantmod)
library(xts)
library(plotly)
library(magrittr)
library(tseries)
library(TTR)
library(tensorflow)
library(keras)
library(tidyverse)
library(caret)
library(ggplot2)
library(GA)
library(zoo)

# Loading the Data:

options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)

# Load data for Microsoft (AAPL)
getSymbols("AAPL")

# Analyzing the time series component only for now but later we are going to use all the stock features for training and modelling.
# Extract adjusted close prices and dates for AAPL
aapl <- Cl(AAPL)
dates <- index(AAPL)

# Create a data frame
df <- data.frame(Date = as.Date(dates),
                 AAPL = as.numeric(aapl))
head(df)

Solution

  • To make a minimal reproducible example remove the options statements since we don't want to suppress warnings if there is something going wrong and also remove all unused library statements -- quantmod already loads xts which loads zoo and the rest are not used. It worked for me on Windows. (continued after code)

    library(quantmod) # quantmod 0.4.26, xts 0.13.2, zoo 1.8.2
    
    ## ...snip output from library statement...
    
    getSymbols("AAPL")
    ## [1] "AAPL"
    
    aapl <- Cl(AAPL)
    dates <- index(AAPL)
    df <- data.frame(Date = as.Date(dates),
                     AAPL = as.numeric(aapl))
    head(df)
    ##         Date     AAPL
    ## 1 2007-01-03 2.992857
    ## 2 2007-01-04 3.059286
    ## 3 2007-01-05 3.037500
    ## 4 2007-01-08 3.052500
    ## 5 2007-01-09 3.306071
    ## 6 2007-01-10 3.464286
    
    R.version.string
    ## [1] "R version 4.3.2 Patched (2023-11-16 r85542 ucrt)"
    

    Check your versions, remove library statements not used, remove the suppression of warnings which may reveal something important and run on a fresh instance of R. Also we can reduce all the lines after getSymbols to

    df <- fortify.zoo(Cl(AAPL))