0

I am trying to use WRDS with R by using this code: enter image description here

I am getting this error:

enter image description here

I tried removing (obs=10) and I did not receive the same error, but when I entered:

enter image description here

The result was:

enter image description here

I tried this:

enter image description here

and got the same error.

  • 1
    Welcome to Stack Overflow. Please don’t use images of code or data as they cannot be used without a lot of unnecessary effort. [For multiple reasons](//meta.stackoverflow.com/q/285551). You’re more likely to get a positive response if your question is reproducible. [See Stack Overflow question guidance](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Peter Mar 24 '22 at 07:10

2 Answers2

0

Try using dbFetch rather than fetch.

res <- dbSendQuery(wrds, "SELECT date, dji FROM djones.djdaily")

data <- dbFetch(res, n = -1)

0

I would say that approaches using dplyr/dbplyr are better when working with the WRDS PostgreSQL database.

To do the equivalent of (obs=10), do something like the following. The real payoff to dbplyr-based approaches comes when merging multiple large tables, which happens on the WRDS PostgreSQL server without needing to download data.

For many more examples like this one, see here.

library(dplyr, warn.conflicts = FALSE)
library(DBI)

pg <- dbConnect(RPostgres::Postgres())

djones.djdaily <- tbl(pg, sql("SELECT * FROM djones.djdaily"))

data <- 
  djones.djdaily %>%
  select(date, dji) %>%
  collect(n = 10)

data
#> # A tibble: 10 × 2
#>    date         dji
#>    <date>     <dbl>
#>  1 1896-05-26  40.9
#>  2 1896-05-27  40.6
#>  3 1896-05-28  40.2
#>  4 1896-05-29  40.6
#>  5 1896-06-01  40.6
#>  6 1896-06-02  40.0
#>  7 1896-06-03  39.8
#>  8 1896-06-04  39.9
#>  9 1896-06-05  40.3
#> 10 1896-06-08  39.8

Created on 2023-02-04 with reprex v2.0.2

Ian Gow
  • 3,098
  • 1
  • 25
  • 31