Retrieving subsets of data with EUtilsGet - r

I am new to r and RISmed, so please accept my apologies if this is a very simple question.
I have been following a tutorial on how to get data on a large number of references from PubMed. When I use:
pubmed_data <- data.frame('Title'=ArticleTitle(records),'Abstract'=AbstractText(records))
head(pubmed_data,1)
It returns the data for Title and Abstract as expected, however when I add instructions to return Author, Journal, Year, Country and Keyword it still only returns the Title and Abstract. What am I missing? I use the following code:
pubmed_data <- data.frame('Title'=ArticleTitle(records),'Abstract'=AbstractText(records), 'Journal'=Journal(records), 'Year'=DateCreated(records), 'Author'=AuthorList(records), 'Country'=Country(records), 'Keyword'=KeywordList(records))
head(pubmed_data,1)

Next to ArticleTitle and AbstractText functions, you're also using Journal, DateCreated, AuthorList, Country, and KeywordList. Some of these functions are not listed directly in the package reference manual (only Country appears to be a valid function).

Related

SpotifyR get_artist_audio_features() doesn't filter by market, is_uri() not found when editing

I'm trying to obtain audio features of an artist's tracks with spotifyr:
test <- get_artist_audio_features("california honeydrops", include_groups = c("album", "single", "appears_on", "compilation"), market = "US")
A quick check of the results reveals several repeats of the same track and album names with slightly different audio features, and unique(test$available_markets reveals that these duplications are because the function did not properly filter by market = "US". Replacing "US" with other country codes yields the same result. However, if include_groups is left as the default, which only returns tracks from albums, then the market filter does work as expected.
I thought I might make a quick fix by editing the source code for get_artist_audio_features() to force market = "US" in RStudio, but I get an error when copy-pasting and then trying to run the original function's code because R insists one of the functions used to make get_artist_audio_features(), spotify::is_uri(), is not part of the spotifyr package. However, it can be found in the package's help section, is part of the original function, and works fine when calling the original function.
Of course, I can filter these duplicates out after the fact, but for edification's sake, what gives? Can anyone provide a fix to the original function or explain why R can't find the is_uri() when I try to run a copy of the original function?

Pulling Portfolio Data From Bloomberg using R Package "Rblpapiā€

I am trying to pull portfolio data from Bloomberg using command getPortfolio(My Portfolio,"Portfolio_Data"). Is it Possible to indicate reference date in the command?
When using excel it is possible to extract a portfolio at a certain point in time using BDS(My Portfolio,"Portfolio_Data","reference date = date") function. I wonder if this is possible in R.
BDS command returns NULL when requesting portfolio data in R. It seems like getPortfolio() should be the right solution, however I cannot figure out how to incorporate date into the function.
Figured out the correct syntax. The way to incorporate reference date into getPortfolio() function should look like the following:
overrides = c("REFERENCE_DATE" = '20181010')
getPortfolio("My Portfolio","Portfolio_Data", overrides = overrides)
"My Portfolio" should be portfolio ID from BBG's PRTU function with "client" appended (should look like this: "U1234567-8 Client")

Using abbreviated code to specify a custom renderer using table1 in R

Hello I don't have many experience with R but I need help using abbreviated code to specify a custom renderer for the "table1" package in R. I would like to not display the default stats(FREQ,PCT) variable for categorical data and only display the frequency and omit the percent. The code in R Documentations show how to customize this for continuous variables and show some custom statistics for different variables.
This is just for the convenience of displaying a frequency table with the built html formatting of package 1. I do know how to get this information otherwise. I am interested learning how to use more this package in R.
rndr <- function(x, name, ...)
{(what <- switch(name,
c_race = "FREQ",
parse.abbrev.render.code(c("", what))(x))
}
table1::table1(~c_race|c_ethnicity*c_gender, data = childlearn_demo,
render=rndr, overall="Total",topclass="Rtable1-zebra")
The purpose of "abbreviated code" is to allow flexibility without needing to write your own function. Thus, you can get the desired result by simply using render.categorical="Freq", i.e.:
table1::table1(~ c_race|c_ethnicity*c_gender, data = childlearn_demo,
overall="Total",topclass="Rtable1-zebra", render.categorical="Freq")
(note: I am the table1 package author)

Problem Getting Data from bsrch Using Rblpapi

I can use bsrch in excel to get values given of "COMDTY:WEATHER" however when I try it using Rblpapi it shows empty data. Also below I have the Excel formulas so you can see how I am trying to get it to work in R below
Observations Basic Query
=BSRCH("comdty:weather","provider=wsi","location=KNYC","model=ACTUALS","cols=15;rows=354")
Observations Specify Parameters
=BSRCH("comdty:weather","provider=wsi","location=KNYC","model=ACTUALS","fields=WIND_SPEED|TEMPERATURE","cols=3;rows=358")
I tried to look for examples online and only found the below, and this code works.
#this code works
library(Rblpapi)
blpConnect()
head(bsrch("COMDTY:NGFLOW"), 20)
head(bsrch("COMDTY:VESSEL"), 20)
#this is my code and it doesn't work
head(bsrch("COMDTY:WEATHER"), 20)
In order to pass in the overrides, requests need to be modified. In this particular request type, the name and value element of values of Overrides array element needs to be modified. In their source code this is not implemented yet, they have a TODO item below.
// TODO - implement limit and other overrides
Hopefully this will be introduced in future versions. Or you can implement yourself.

How/where to match tidycensus variables with census bureau variables?

Problem
I am given a long list of specific variable codes for the DP05 table - in the census bureau format. For instance:
target_dp05_vars = c(perc_white = "HC03_VC53",
perc_black = "HC03_VC55",
perc_native = "HC03_VC56")
Since tidycensus uses its own variable naming convention, I can't use the above easily. How do I easily crosswalk to the tidycensus definition?
Temporary solution
In the meantime, I've downloaded the bureau file manually and eliminated rows with HC02 and HC04 prefixes to match with tidycensus to create an internal crosswalk (because it's at least positionally correct) but it's tedious.
I'd love to just feed those HCs as a named vector into get_acs() and perhaps just specify the table as DP05.
tidycensus doesn't use its own variable naming convention - it uses variable IDs as specified by the Census API. For example, see https://api.census.gov/data/2017/acs/acs5/profile/variables.html, which is accessible in R with:
library(tidycensus)
dp17 <- load_variables(2017, "acs5/profile", cache = TRUE)
The IDs you've provided appear to be FactFinder codes.
If you want the full DP05 table in one tidycensus call, you can do the following (e.g. for counties in New York) with tidycensus 0.9:
dp05 <- get_acs(geography = "county",
table = "DP05",
state = "NY")
Mapping of variable IDs to their meanings are in turn available with load_variables().
Note: I am getting intermittent server errors with these calls from the API, which may be due to the government shutdown. If it doesn't work at first, try again.

Resources