Matt-Brigida / EIAdata

R Wrapper for the Energy Information Administration (EIA) API
16 stars 15 forks source link

Error in order(date) : argument 1 is not a vector #16

Closed Islascuevas closed 2 years ago

Islascuevas commented 2 years ago

Hi! I have been using EIAdata successfully for months but yesterday the error in the title appeared. The code that I have is the following:

`library(EIAdata) library(openxlsx)

PETROLEO

WTI_Crude_Oil_price<-getEIA("STEO.WTIPUUS.M", "063ecd96bd98ad1ab099fbb524b194c2")

BRENT_Spot_price <-getEIA("STEO.BREPUUS.M", "063ecd96bd98ad1ab099fbb524b194c2")

GASOLINAS

gulf_coast_all_grades_conventional_retail_gasoline_prices<-getEIA("PET.EMM_EPM0U_PTE_R30_DPG.M", "063ecd96bd98ad1ab099fbb524b194c2")

gulf_coast_regular_conventional_retail_gasoline_prices<-getEIA("STEO.MGRARP3.M", "063ecd96bd98ad1ab099fbb524b194c2")

gulf_coast_premium_conventional_retail_gasoline_prices <- getEIA("PET.EMM_EPMPU_PTE_R30_DPG.M", "063ecd96bd98ad1ab099fbb524b194c2")

US_Gulf_Coast_Ultra_Low_Sulfur_No2_Diesel_Spot_Price<-getEIA("PET.EER_EPD2DXL0_PF4_RGC_DPG.M","063ecd96bd98ad1ab099fbb524b194c2")

diesel_fuel_refiner_prices<-getEIA("STEO.DSWHUUS.M","063ecd96bd98ad1ab099fbb524b194c2")

GAS NATURAL

Henry_Hub_Spot_Price <- getEIA("STEO.NGHHUUS.M","063ecd96bd98ad1ab099fbb524b194c2")

ELECTRICIDAD

Cost_of_Coal_Delivered_To_Electric_Generating_Plants<-getEIA("STEO.CLEUDUS.M","063ecd96bd98ad1ab099fbb524b194c2")

Fuel_Oil<-getEIA("STEO.RFEUDUS.M","063ecd96bd98ad1ab099fbb524b194c2")

Gas LP

Mont_Belvieu_Spot_Prices<- getEIA("PET.EER_EPLLPA_PF4_Y44MB_DPG.M","063ecd96bd98ad1ab099fbb524b194c2")`

Matt-Brigida commented 2 years ago

I am not able to reproduce this error. Everything seems to be working---possibly it was a temporary error on the EIA's side. Can you try again and let me know if you run into any issues?

Islascuevas commented 2 years ago

Hi, I tried again and the error still occurs image

acmccullagh commented 2 years ago

I have the same issue--had been running the package daily for years, started getting an error on 11/9. Here's a code snippet: library(EIAdata) getEIA(ID="ELEC.GEN.COW-US-98.M", key="958da683c000674e86ce301d277beea7") Capture

Matt-Brigida commented 2 years ago

Interesting. I'll take a look at this today. Can you include the output of sessionInfo() after loading EIAdata? This error is likely due to package/R/OS versions since I can't reproduce it on the latest version of R (4.1.2) on Linux. Note, @Islascuevas and @acmccullagh you are running R 3.6.3 with is from Feb 2020.

Matt-Brigida commented 2 years ago

date = sapply(doc["//data/row/date"], XML::xmlValue),

`df <- df[ with(df, order(date)), ]` @Islascuevas @acmccullagh Above are the relevant lines of code throwing the error. `date` is produced via a function from the `XML` package. So I am guessing that is where the problem is. You may want to ensure you are running the latest version of XML built on R 4.1.2.
Islascuevas commented 2 years ago

Thanks Matt, I downloaded the R.4.1.2. version and updated the XML package but the error still appears

image

acmccullagh commented 2 years ago

yes, thanks so much for your help--similarly I get the same error after updating image

Islascuevas commented 2 years ago

This is the output of sessionInfo() image

Matt-Brigida commented 2 years ago

I tried using your key and I am able to reproduce the problem:

getEIA("STEO.BREPUUS.M", key = "063ECD96BD98AD1AB099FBB524B194C2") Error in order(date) : argument 1 is not a vector

However using my key (what I have been using):

head(getEIA("STEO.WTIPUUS.M", key=key), 2) STEO.WTIPUUS.M ## 1990-01-01 22.863 ## 1990-02-01 22.113

So it looks like your key is the issue. Note the code doesn't explicitly test for a valid key, though given your error I may change it to do so. I would try a new key, that should work. Of course, let me know if it doesn't.

@Islascuevas @acmccullagh and thanks for posting your session info. Since all our package versions were the same after upgrade, it allowed me to look elsewhere.

sawyervillers commented 2 years ago

I had the same issue. It looks like an issue with the EIA. I went to the EIA API webpage and attempted to recover my key, and they said I wasn't registered. I then registered and received a new key, and the getEIA function worked.

Matt-Brigida commented 2 years ago

@sawyervillers Thanks for confirming! I'll close the issue.