Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request #4 from us-bea/master #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Merge pull request #4 from us-bea/master #5

wants to merge 1 commit into from

Conversation

Hamed51
Copy link

@Hamed51 Hamed51 commented Mar 13, 2018

@DreaJulca
Hello,
I am starting to use Bea API for R. i am trying to get data from Regional Income
Method' = 'GetData',
'Datasetname' = 'RegionalIncome',
'GeoFips'='STATE',
'TableName' = 'SA51',
'Year' = 'ALL',
'ResultFormat' = 'json'
and this the error that i get:$BEAAPI$Results
$BEAAPI$Results$Error
$BEAAPI$Results$Error$APIErrorCode
[1] "40"

$BEAAPI$Results$Error$APIErrorDescription
[1] "The dataset requested requires parameters that were missing from the request."

$BEAAPI$Results$Error$AdditionalDetail
$BEAAPI$Results$Error$AdditionalDetail$MissingParameter
$BEAAPI$Results$Error$AdditionalDetail$MissingParameter$ParameterName
[1] "LineCode"

$BEAAPI$Results$Error$AdditionalDetail$MissingParameter$ParameterDescription
[1] "Line code for a statistic or industry"

could you help me how i get the line code? or in general , how to solve this problem?

thank you,

@DreaJulca
Copy link
Collaborator

DreaJulca commented Mar 14, 2018

Hi @Hamed51,

BEA's API has a new method, "GetParameterValuesFiltered", for getting the values you can enter for a given parameter, filtering for a selection of the other parameters you would like to pass.

A higher-level wrapper for this method hasn't been incorporated into the bea.R library yet, but you can pass a beaGet() request with parameters to give you possible values.

In the case of your specific query, where you want to find the possible LineCode values given that you are looking for table SA51, you would want to use something like the following:

   lcSpecs <- list(
	'UserID' = beaKey, 
	'Method' = 'GetParameterValuesFiltered',
	'Datasetname' = 'RegionalIncome',
	'TableName' = 'SA51',
	'TargetParameter' = 'LineCode'
  )

  lcResp <- beaGet(lcSpecs, asTable = F, asList = T, isMeta = T)

  lcResp$ParamValue

Where the variable "beaKey" is a character string with your 36-digit BEA API key.

"lcResp$ParamValue" will be a table with a "Key" column (the value you should enter in your user specifications list, as "LineCode" = [the key you want]) and a "Desc" column (a description of what that line code refers to).

In this case, your lcResp$ParamValue should be:

      Key                                         Desc
1     51            [SA51] Disposable personal income
2     52            [SA51] Population
3     53            [SA51] Per capita disposable personal income

In future versions bea.R, we will add a method for retrieving this information that is more comparable to the existing "beaParamVals()" function (see ?beaParamVals).

Thanks for letting us know about this! If you have any follow-up questions or issues, feel free to comment with them here. For more information about the "GetParameterValuesFiltered" method, check the "Methods" tab of our API manual

@Hamed51
Copy link
Author

Hamed51 commented Mar 14, 2018 via email

@DreaJulca
Copy link
Collaborator

Whenever I release a patch or update, I create a new release version in this repository. You can watch the repository by going to the main repo page and selecting the "Watch" option in the upper right corner in your browser.

Since I create a new version at the same time as my CRAN submission, this means you can keep an eye out for a new version on the CRAN page; the R core team is really fast about approving updates to packages--typically it happens within a few days (barring any major issues with the new version).

@Hamed51
Copy link
Author

Hamed51 commented Mar 22, 2018

@DreaJulca
Hello,
I got Real Value Added by Industry by creating this request ::indus <- list(
'UserID' = mykey,
'Method' = 'GetData',
'Datasetname' = 'GDPbyIndustry',
"TableID"='10',
'Frequency' = 'Q',
"Year"="All",
"Industry"="All"
)
beaGet(indus, asTable = F, asList = T, isMeta = T).
I have been trying to get Real Gross Output by Industry data by changing the TableID to 208 ("TableID"='208'), but i got this error::

Error: lexical error: invalid character inside string.
series, divided by 100. Because the formula for the c
(right here) ------^

i could not access to data whenever i try to get. is it related to R or server. could you advise me how to get the data?

Thank You

@Hamed51
Copy link
Author

Hamed51 commented Mar 23, 2018 via email

@DreaJulca
Copy link
Collaborator

Hi @Hamed51 ,

Looks like there's a carriage return in a new reference notes in the API response, and it seems that jsonlite (a dependency of bea.R) can't handle it because it is breaking the JSON into multiple lines within a string element.

I'll see if there is anything we can do about removing carriage returns from our API responses (or, barring that, patch bea.R), but in the meantime, here's a workaround:

#Get the response without any conversion
lcResp <- beaGet(indus, asTable = F)

#Remove carriage return in response string, convert back to raw bytes
lcResp$content <- charToRaw(gsub('[\r\n]', '', content(lcResp, as='text')))

#Convert response to data.table using bea.R::bea2Tab()
indData <- bea2Tab(lcResp)

Thanks for bringing this to my attention!

@Hamed51
Copy link
Author

Hamed51 commented Mar 24, 2018 via email

@PhilSmith26
Copy link

I am a new user of the bea.R API, with RStudio. I can successfully retrieve NIPA tables, but I have been unable to retrieve the GDPbyIndustry table(s) that were released for the first time by BEA on September 30, 2020 (Table 12 in the NIPA press release in particular). I cannot seem to get the beaSpec right. It says "The dataset requested requires parameters that were missing from the request." When I tried the GetParameterValuesFiltered method, it said "The GetParameterValuesFiltered method has not been implemented on this dataset (coming soon)." Is there a way to retrieve the GDPbyIndustry table?

Philip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants