'getsymbol cannot finish the whole downloading process when the share price of batch of stocks is downloaded in R from YAHOO

Recently, when I download the share price of batch of share list from yahoo, the downloading process always is stopped suddenly without any warning.

Below is the code,

library(quantmod)
library(openxlsx)
df<-read.xlsx("C:/Users/USER/Documents/R/technical analysis v2/Stock_Name_selected_v3.xlsx",sheet=1)
stock_list<-df$Stock.code
stock_name<-df$Name
e <- new.env()
buy_sell <- rep(0,nrow(df))


get_stock<-function(x,from1) 
{
  message=paste0("Now getting the stock figures for:",x)
  print(message)
  df<-suppressWarnings(getSymbols(x,from=from1,auto.assign = F))
  #df<-tryCatch(getSymbols(x,from=from1,auto.assign = F),error=function(error_message){return(NULL)})
  df<-adjustOHLC(df, use.Adjusted=T)
  df<-na.locf(df)
  colnames(df)<-c("Open","High","Low","Close","Volume","Adjusted")
  end_date<-"2022-05-10"
  #if (nrow(df[index(df)==end_date-1,])>1){df<-head(df,-1)}
  #return(tryCatch(df,error=function(error_message) {return(NULL)}))
  return(df)
  
}

#L_df<-lapply(stock_list,function(x) get_stock(x,from1="2015-01-01"))

L_df<-lapply(stock_list,function(x) tryCatch(get_stock(x,from1="2022-01-01"),error=function(error_message) {
  message("This is my custom message.")
  message("And below is the error message from R:")
  message(error_message)
  return(NULL)
}))

When running the code above, the process stops at

[1] "Now getting the stock figures for:0700.HK" [1] "Now getting the stock figures for:0005.HK"

But there are 41 stock and the excel has two columns as below,

Stock code  Name
0700.HK HK0700
0005.HK HK0005
0788.HK HK0788
7500.HK HK7500
2269.HK HK2269
1810.HK HK1800
0001.HK HK0001
0016.HK HK0016
0002.HK HK0002
1800.HK HK1800
0388.HK HK0388
1818.HK HK1818
0135.HK HK0135
0027.HK HK0027
9988.HK HK9988
0941.HK HK0941
2822.HK HK2822
2840.HK HK2840
7299.HK HK7299
1833.HK HK1833
1361.HK HK1361
0855.HK HK0855
0688.HK HK0688
0883.HK HK0883
7200.HK HK7200
0386.HK HK0386
3993.HK HK3993
7568.HK HK7568
1299.HK HK1299
2007.HK HK2007
2196.HK HK2196
2899.HK HK2899
6169.HK HK6169
0992.HK HK0992
2382.HK HK2382
0081.HK HK0081
0151.HK HK0151
1986.HK HK1986
2009.HK HK2009
1988.HK HK1988

Before end of April this year, I do not have similar issue. Could you check whether you can run the whole downloading process? Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source