0

I tried now for some time to simply download a csv file in RStudio(so i am using R) from the web. I have done stuff like this before and never run into the issues i have now. Tried several solutions suggested online. I simply try to download the following file from here https://www.nasdaq.com/market-activity/stocks/aapl/historical. This is the link to the csv -> https://www.nasdaq.com/api/v1/historical/AAPL/stocks/2020-09-09/2020-10-09. I tried httr and RCurl package methods none worked. Hope someone can help me out, thanks in advance.

Edit: What i tried so far: -Updated ssl -I can install new packages so internet generally works -Updated git -Updated R -Updated all packages -Tried what is suggested here: Download.file fails in RStudio

Edit2: A while ago i did webscrape with the package RSelenium and started a rem_session. Is it possible that Rselenium changes some underlying settings?

Edit3: Completely uninstalled Rstudio + R + Rtool manually deleted everything, after a fresh installation still the same problem

BroNKo
  • 39
  • 7
  • maybe you can try to uninstall **RSelenium** with `remove.packages()` or to create a new project with no packages linked, using `renv::init(bare = TRUE)`. then, check if your problem is gone.. – rodolfoksveiga Oct 09 '20 at 16:09
  • Thanks for your reply, but after reinstallation everything, Rstudio etc. no packages were available anyway. I rather thought mabey ports are changed or something idk. I tried everything nothing worked... also i seem to be the only one with this problem... Still tried what you suggested anyway. No success tho – BroNKo Oct 09 '20 at 19:07

2 Answers2

0

Have you tried to load it directly in R through read.csv()?

It worked for me... Check it out:

data = read.csv('https://www.nasdaq.com/api/v1/historical/AAPL/stocks/2020-09-09/2020-10-09')
data

Here is the output:

         Date Close.Last    Volume     Open      High      Low
1  10/07/2020    $115.08  96848990  $114.62   $115.55  $114.13
2  10/06/2020    $113.16 161498200   $115.7   $116.12  $112.25
3  10/05/2020     $116.5 106243800  $113.91   $116.65  $113.55
4  10/02/2020    $113.02 144712000  $112.89   $115.37  $112.22
5  10/01/2020    $116.79 116120400  $117.64   $117.72  $115.83
6  09/30/2020    $115.81 142675200  $113.79   $117.26  $113.62
7  09/29/2020    $114.09 100060500  $114.55   $115.31  $113.57
8  09/28/2020    $114.96 137672400  $115.01   $115.32  $112.78
9  09/25/2020    $112.28 149981400  $108.43   $112.44  $107.67
10 09/24/2020    $108.22 167743300  $105.17   $110.25     $105
11 09/23/2020    $107.12 150718700  $111.62   $112.11  $106.77
12 09/22/2020    $111.81 183055400  $112.68   $112.86  $109.16
13 09/21/2020    $110.08 195713800  $104.54   $110.19   $103.1
14 09/18/2020    $106.84 287104900   $110.4   $110.88  $106.09
15 09/17/2020    $110.34 178011000  $109.72    $112.2  $108.71
16 09/16/2020    $112.13 155026700  $115.23      $116  $112.04
17 09/15/2020    $115.54 184642000  $118.33  $118.829  $113.61
18 09/14/2020   $115.355 140150100  $114.72   $115.93   $112.8
19 09/11/2020       $112 180860300  $114.57   $115.23     $110
20 09/10/2020    $113.49 182274400  $120.36    $120.5   $112.5
21 09/09/2020    $117.32 176940500  $117.26   $119.14  $115.26

If you want to save it afterwards as a csv file, just run write.csv():

write.csv(data, '~/Downloads/data.csv')

Let me know if it worked for you.

rodolfoksveiga
  • 1,181
  • 4
  • 17
  • Thanks for your help. Now i know that my issue is not in respect to that specific csv file. The error i receive is -> InternetOpenUrl failed: 'Das Zeitlimit f�r den Vorgang wurde erreicht.'Error in file(file, "rt") : cannot open the connection. I edited my question above to give further information. – BroNKo Oct 09 '20 at 09:36
0

In case you are in a windows OS you need to set the mode=wb argument.

download.file(
    "https://www.nasdaq.com/api/v1/historical/AAPL/stocks/2020-09-09/2020-10-09",
     "file.csv", mode='wb'
)
Johan Rosa
  • 2,797
  • 10
  • 18
  • Thanks for your help. Now i know that my issue is not in respect to that specific csv file. The error i receive is -> trying URL 'https://www.nasdaq.com/api/v1/historical/AAPL/stocks/2020-09-09/2020-10-09' InternetOpenUrl failed: 'Das Zeitlimit f�r den Vorgang wurde erreicht.'Error in download.file("https://www.nasdaq.com/api/v1/historical/AAPL/stocks/2020-09-09/2020-10-09", : cannot open URL 'https://www.nasdaq.com/api/v1/historical/AAPL/stocks/2020-09-09/2020-10-09'. I edited my question above to give further information. – BroNKo Oct 09 '20 at 09:34