### Example usage of total_distributors_county Source: https://wpinvestigative.github.io/arcos/reference/total_distributors_county.html Shows a practical example of using `total_distributors_county` to get distribution data for Mingo County, WV, and then displaying the first few rows of the result. This is helpful for understanding the function's output format. ```r # \donttest{ library(arcos) mingo_wv <- total_distributors_county(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) # > BUYER_STATE buyer_county Reporter_family total_dosage_unit # > 1 WV MINGO AmerisourceBergen Drug 3701200 # > 2 WV MINGO Anda, Inc 82400 # > 3 WV MINGO Associated Pharmacies Inc 1500 # > 4 WV MINGO Auburn Pharmaceutical 17700 # > 5 WV MINGO Butler Animal Health Supply 700 # > 6 WV MINGO Cardinal Health 3979150 # > total_records # > 1 4292 # > 2 89 # > 3 1 # > 4 10 # > 5 4 # > 6 5915 # } ``` -------------------------------- ### Example usage of total_manufacturers_county Source: https://wpinvestigative.github.io/arcos/reference/total_manufacturers_county.html This example demonstrates how to use the `total_manufacturers_county` function to get data for Mingo County, WV, and then displays the first few rows of the result. ```r # \donttest{ library(arcos) mingo_wv <- total_manufacturers_county(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> buyer_state buyer_county combined_labeler_name total_dosage_unit #> 1 WV MINGO AAI Pharma 11100 #> 2 WV MINGO AbbVie Inc. 95100 #> 3 WV MINGO Actavis Pharma, Inc. 31142920 #> 4 WV MINGO Allergan, Inc. 200 #> 5 WV MINGO Alvogen, Inc. 42100 #> 6 WV MINGO Amneal Pharmaceuticals LLC 213600 #> total_records #> 1 31 #> 2 399 #> 3 23127 #> 4 2 #> 5 147 #> 6 794 # } ``` -------------------------------- ### Install and Load Required R Packages Source: https://wpinvestigative.github.io/arcos/articles/county-analysis.html Installs and loads necessary R packages for data analysis and visualization. Ensure these packages are installed before running the analysis. ```r # Uncomment and run the lines below to see if you have the packages required already installed # packages <- c("tidyverse", "jsonlite", "knitr", "geofacet", "scales", "forcats") # if (length(setdiff(packages, rownames(installed.packages()))) > 0) { # install.packages(setdiff(packages, rownames(installed.packages())), repos = "http://cran.us.r-project.org") # } # These are all the packages you'll need to run everything below library(arcos) library(knitr) library(tigris) library(viridis) library(dplyr) library(ggplot2) library(scales) library(forcats) ``` -------------------------------- ### Example usage of not_pharmacies Source: https://wpinvestigative.github.io/arcos/reference/not_pharmacies.html Demonstrates how to use the `not_pharmacies` function to get a list of misidentified pharmacies and view the first few results. ```r # \donttest{ library(arcos) np <- not_pharmacies(key="WaPo") head(np) # } ``` -------------------------------- ### Example Usage of pharm_tracts Source: https://wpinvestigative.github.io/arcos/reference/pharm_tracts.html Shows a practical example of using the `pharm_tracts` function to get pharmacy data for Mingo County, WV, and then displays the first few rows of the result. ```r # \donttest{ library(arcos) mingo_wv <- pharm_tracts(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) ``` -------------------------------- ### Call total_distributors_state function Source: https://wpinvestigative.github.io/arcos/reference/total_distributors_state.html This is a basic example of how to call the `total_distributors_state` function with a state and key. It shows the minimal arguments required. ```r total_distributors_state(state = "WV", key = "WaPo") ``` -------------------------------- ### Load and display total distributors by state data Source: https://wpinvestigative.github.io/arcos/reference/total_distributors_state.html This example demonstrates how to load the `arcos` library, call the `total_distributors_state` function to get data for West Virginia, and then display the first few rows of the resulting data frame. ```r # \donttest{ library(arcos) wv <- total_distributors_state(state="WV", key="WaPo") head(wv) #> buyer_state buyer_county Reporter_family total_dosage_unit #> 1 WV CABELL AmerisourceBergen Drug 27564760 #> 2 WV KANAWHA Rite Aid 18987950 #> 3 WV KANAWHA Cardinal Health 18418060 #> 4 WV HARRISON Cardinal Health 15477110 #> 5 WV HANCOCK Cardinal Health 12907450 #> 6 WV LOGAN McKesson Corporation 12548310 #> total_records #> 1 51557 #> 2 29772 #> 3 52962 #> 4 36515 #> 5 31477 #> 6 15677 # } ``` -------------------------------- ### Retrieve and display monthly pill data for a county Source: https://wpinvestigative.github.io/arcos/reference/combined_buyer_monthly.html This example demonstrates how to use the `combined_buyer_monthly` function to get monthly pill data for a specific county ('Mingo', 'WV') in a given year (2012). It then displays the first few rows of the resulting data frame. ```r # \donttest{ library(arcos) mingo_wv <- combined_buyer_monthly(county = "Mingo", state="WV", year=2012, key="WaPo") head(mingo_wv) #> BUYER_DEA_NO BUYER_BUS_ACT BUYER_COUNTY BUYER_STATE year month DOSAGE_UNIT #> 1 AA8151728 RETAIL PHARMACY MINGO WV 2012 01 18800 #> 2 AA8151728 RETAIL PHARMACY MINGO WV 2012 02 20700 #> 3 AA8151728 RETAIL PHARMACY MINGO WV 2012 03 16100 #> 4 AA8151728 RETAIL PHARMACY MINGO WV 2012 04 23100 #> 5 AA8151728 RETAIL PHARMACY MINGO WV 2012 05 19400 #> 6 AA8151728 RETAIL PHARMACY MINGO WV 2012 06 17400 # } ``` -------------------------------- ### Retrieve and display total manufacturers data for a state Source: https://wpinvestigative.github.io/arcos/reference/total_manufacturers_state.html This example demonstrates how to use the `total_manufacturers_state` function to get data for West Virginia and then display the first few rows of the result using `head()`. ```r library(arcos) wv <- total_manufacturers_state(state="WV", key="WaPo") head(wv) ``` -------------------------------- ### Load arcos and Get Pharmacy Addresses Source: https://wpinvestigative.github.io/arcos/reference/buyer_addresses.html This example shows how to load the `arcos` library and then use the `buyer_addresses` function to retrieve pharmacy data for Mingo County, WV. It also displays the first few rows of the resulting data frame. ```r library(arcos) mingo_wv <- buyer_addresses(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) ``` -------------------------------- ### Install Development Version from GitHub Source: https://wpinvestigative.github.io/arcos/index.html Installs the development version of the arcos package from GitHub. Requires the devtools package. ```r # install.packages("devtools") devtools::install_github('wpinvestigative/arcos') ``` -------------------------------- ### Example of total_pharmacies_county usage Source: https://wpinvestigative.github.io/arcos/reference/total_pharmacies_county.html This example demonstrates how to call the `total_pharmacies_county` function and then view the first few rows of the resulting data frame, which includes pharmacy details and total dispensed pills. ```r # \donttest{ library(arcos) mingo_wv <- total_pharmacies_county(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> buyer_state buyer_county buyer_dea_no buyer_name buyer_city #> 1 WV MINGO BS7437064 STROSNIDER KERMIT #> 2 WV MINGO BH6954401 HURLEY DRUG COMPANY INC WILLIAMSON #> 3 WV MINGO FT0251227 TUG VALLEY PHARMACY, LLC WILLIAMSON #> 4 WV MINGO FR0261684 RIVERSIDE PHARMACY GILBERT #> 5 WV MINGO AA8151728 ADKINS PHARMACY INC GILBERT #> 6 WV MINGO FG0153863 GILBERT PHARMACY GILBERT #> total_dosage_unit total_records #> 1 13168350 7691 #> 2 8890370 11138 #> 3 8827860 5390 #> 4 1780680 2249 #> 5 1576200 2491 #> 6 1403720 3138 # } ``` -------------------------------- ### Retrieve and display summarized buyer details Source: https://wpinvestigative.github.io/arcos/reference/buyer_details.html This example demonstrates how to use the `buyer_details` function to fetch data for a specific county and state, then display the first few rows of the result. Ensure the 'arcos' library is loaded. ```r # \donttest{ library(arcos) mingo_wv <- buyer_details(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> BUYER_DEA_NO BUYER_BUS_ACT BUYER_NAME #> 1 BH6954401 RETAIL PHARMACY HURLEY DRUG COMPANY INC #> 2 BS7437064 RETAIL PHARMACY STROSNIDER #> 3 FS1092787 RETAIL PHARMACY SAV-RITE PHARMACY #2 #> 4 FT0251227 RETAIL PHARMACY TUG VALLEY PHARMACY, LLC #> 5 BM2933263 RETAIL PHARMACY MATEWAN FAMILY PHARMACY, INC #> 6 FR0261684 RETAIL PHARMACY RIVERSIDE PHARMACY #> BUYER_ADDRESS1 BUYER_CITY BUYER_STATE BUYER_ZIP BUYER_COUNTY #> 1 210 LOGAN STREET WILLIAMSON WV 25661 MINGO #> 2 PO BOX 600 KERMIT WV 25674 MINGO #> 3 ROUTE 52 STONECOAL ROAD KERMIT WV 25674 MINGO #> 4 PO BOX 538 WILLIAMSON WV 25661 MINGO #> 5 RT. 49, MAIN ST. MATEWAN WV 25678 MINGO #> 6 22 LARRY JOE HARLESS DR GILBERT WV 25621 MINGO #> BUYER_ADDL_CO_INFO BUYER_ADDRESS2 #> 1 #> 2 DBA: SAV-RITE PHARMACY 50 LINCOLN STREET #> 3 STROSNIDER DRUG P.O. BOX 660 #> 4 54 W 2ND AVE #> 5 #> 6 # } ``` -------------------------------- ### Install Required R Packages Source: https://wpinvestigative.github.io/arcos/articles/per-capita-pharmacies.html Installs R packages if they are not already present on the system. This is a prerequisite for running the subsequent analysis. ```r # Uncomment and run the lines below to see if you have the packages required already installed # packages <- c("dplyr", "jsonlite", "knitr", "geofacet", "scales") # if (length(setdiff(packages, rownames(installed.packages()))) > 0) { # install.packages(setdiff(packages, rownames(installed.packages())), repos = "http://cran.us.r-project.org") # } library(arcos) library(dplyr) library(lubridate) library(data.table) library(formattable) library(vroom) library(stringr) library(scales) library(knitr) ``` -------------------------------- ### Retrieve and display annual buyer data Source: https://wpinvestigative.github.io/arcos/reference/combined_buyer_annual.html This example demonstrates how to use the `combined_buyer_annual` function to get data for Mingo County, WV, and then displays the first few rows of the resulting data frame using `head()`. ```R # \donttest{ library(arcos) mingo_wv <- combined_buyer_annual(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> BUYER_DEA_NO BUYER_BUS_ACT BUYER_COUNTY BUYER_STATE year DOSAGE_UNIT #> 1 AA8151728 RETAIL PHARMACY MINGO WV 2006 279800 #> 2 AA8151728 RETAIL PHARMACY MINGO WV 2007 252400 #> 3 AA8151728 RETAIL PHARMACY MINGO WV 2008 219400 #> 4 AA8151728 RETAIL PHARMACY MINGO WV 2009 192000 #> 5 AA8151728 RETAIL PHARMACY MINGO WV 2010 181600 #> 6 AA8151728 RETAIL PHARMACY MINGO WV 2011 211800 # } ``` -------------------------------- ### Load Required R Packages Source: https://wpinvestigative.github.io/arcos/articles/annual-maps.html Installs and loads necessary R packages for data manipulation, plotting, and API interaction. Ensure these packages are installed before running the script. ```r # Uncomment and run the lines below to see if you have the packages required already installed # packages <- c("dplyr", "ggplot2", "jsonlite", "knitr", "geofacet", "scales") # if (length(setdiff(packages, rownames(installed.packages()))) > 0) { # install.packages(setdiff(packages, rownames(installed.packages())), repos = "http://cran.us.r-project.org") # } # These are all the packages you'll need to run everything below library(dplyr) library(ggplot2) library(arcos) library(jsonlite) library(knitr) library(geofacet) library(scales) ``` -------------------------------- ### Load and display county population data Source: https://wpinvestigative.github.io/arcos/reference/county_population.html This example demonstrates how to load the `arcos` library, call the `county_population` function to get data for Mingo County, WV, and then display the first few rows of the resulting data frame. ```r # \donttest{ library(arcos) mingo_wv <- county_population(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> BUYER_COUNTY BUYER_STATE countyfips STATE COUNTY county_name #> 1 MINGO WV 54059 54 59 Mingo #> 2 MINGO WV 54059 54 59 Mingo #> 3 MINGO WV 54059 54 59 Mingo #> 4 MINGO WV 54059 54 59 Mingo #> 5 MINGO WV 54059 54 59 Mingo #> 6 MINGO WV 54059 54 59 Mingo #> NAME variable year population #> 1 Mingo County, West Virginia B01003_001 2006 27054 #> 2 Mingo County, West Virginia B01003_001 2007 27145 #> 3 Mingo County, West Virginia B01003_001 2008 26850 #> 4 Mingo County, West Virginia B01003_001 2009 26562 #> 5 Mingo County, West Virginia B01003_001 2010 26956 #> 6 Mingo County, West Virginia B01003_001 2011 26859 # } ``` -------------------------------- ### Install Latest Stable Release from CRAN Source: https://wpinvestigative.github.io/arcos/index.html Installs the latest stable version of the arcos package from CRAN. ```r install.packages("arcos") ``` -------------------------------- ### Get Pharmacy CBSA Data for a Specific GEOID Source: https://wpinvestigative.github.io/arcos/reference/pharm_cbsa.html This example shows how to use the `pharm_cbsa` function to retrieve pharmacy data for a given GEOID. It requires the `arcos` library to be loaded and an API key for the Washington Post data. The output is then displayed using `head()`. ```r # \donttest{ library(arcos) mingo_wv <- pharm_cbsa(geoid="26580", key="WaPo") head(mingo_wv) #> ``` -------------------------------- ### Load and display pharmacy pill data for West Virginia Source: https://wpinvestigative.github.io/arcos/reference/total_pharmacies_state.html This example demonstrates how to load the pharmacy pill data for West Virginia using the `total_pharmacies_state` function and then display the first few rows of the resulting data frame. ```r # \donttest{ library(arcos) wv <- total_pharmacies_state(state="WV", key="WaPo") head(wv) #> ``` -------------------------------- ### Retrieve and Display Summarized County Annual Data Source: https://wpinvestigative.github.io/arcos/reference/summarized_county_annual.html This example demonstrates how to load the `arcos` library, call the `summarized_county_annual` function to get data for Mingo County, WV, and then display the first few rows of the resulting data frame using `head()`. ```r # \donttest{ library(arcos) mingo_wv <- summarized_county_annual(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> BUYER_COUNTY BUYER_STATE year count DOSAGE_UNIT countyfips #> 1 MINGO WV 2006 4192 4691980 54059 #> 2 MINGO WV 2007 5389 7511830 54059 #> 3 MINGO WV 2008 7496 9795100 54059 #> 4 MINGO WV 2009 7227 7464630 54059 #> 5 MINGO WV 2010 4466 3162950 54059 #> 6 MINGO WV 2011 4243 2863950 54059 # } ``` -------------------------------- ### Load and display pharmacy county data Source: https://wpinvestigative.github.io/arcos/reference/pharm_counties.html Shows how to load the `arcos` library, call the `pharm_counties` function to get data for Mingo County, WV, and then display the first few rows of the resulting data frame. ```r # \donttest{ library(arcos) mingo_wv <- pharm_counties(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> BUYER_DEA_NO BUYER_COUNTY BUYER_STATE STATEFP COUNTYFP county_fips #> 1 BM2933263 MINGO WV 54 059 54059 #> 2 AM2373051 MINGO WV 54 059 54059 #> 3 BM2373051 MINGO WV 54 059 54059 #> 4 FM2252372 MINGO WV 54 099 54099 #> 5 FS1092787 MINGO WV 54 099 54099 #> 6 BH6954401 MINGO WV 54 059 54059 # } ``` -------------------------------- ### Retrieve and inspect buyer list Source: https://wpinvestigative.github.io/arcos/reference/buyer_list.html Shows how to load the arcos library, call the `buyer_list` function with a key, and then display the first few rows of the resulting data frame. ```r # \donttest{ library(arcos) bl <- buyer_list(key="WaPo") head(bl) # > BUYER_BUS_ACT total_bus # > 1 ANALYTICAL LAB 988 # > 2 AUTOMATED DISPENSING SYSTEM 10 # > 3 CANINE HANDLER 21 # > 4 CENTRAL FILL PHARMACY 143 # > 5 CHAIN HOSP/CLINIC 113 # > 6 CHAIN PHARMACY 47945 # } ``` -------------------------------- ### Call buyer_list function Source: https://wpinvestigative.github.io/arcos/reference/buyer_list.html Demonstrates how to call the `buyer_list` function with an API key. This is the primary way to retrieve the list of business types. ```r buyer_list(key = "WaPo") ``` -------------------------------- ### Call buyer_details function Source: https://wpinvestigative.github.io/arcos/reference/buyer_details.html This snippet shows a basic call to the `buyer_details` function with required arguments: county, state, and key. ```r buyer_details(county = "Mingo", state = "WV", key = "WaPo") ``` -------------------------------- ### Call total_pharmacies_state with state and key Source: https://wpinvestigative.github.io/arcos/reference/total_pharmacies_state.html This snippet shows the basic usage of the `total_pharmacies_state` function, specifying the state and the required API key. ```r total_pharmacies_state(state = "WV", key = "WaPo") ``` -------------------------------- ### Get Pharmacy Lat/Lon by County and State Source: https://wpinvestigative.github.io/arcos/reference/pharm_latlon.html Use this function to get latitude and longitude for pharmacies within a specific county and state. Ensure you have the necessary API key. ```r pharm_latlon(county = "Mingo", state = "WV", key = "WaPo") ``` ```r # \donttest{ library(arcos) mingo_wv <- pharm_latlon(county = "Mingo", state="WV", key="WaPo") head(mingo_wv) #> BUYER_DEA_NO BUYER_STATE BUYER_COUNTY lat lon #> 1 FG0153863 WV MINGO 37.6114 -81.8634 #> 2 FR0261684 WV MINGO 37.6114 -81.8634 #> 3 AA8151728 WV MINGO 37.6026 -81.8702 #> 4 BR0780521 WV MINGO 37.6125 -81.8713 #> 5 BM2933263 WV MINGO 37.6219 -82.1631 #> 6 AM2373051 WV MINGO 37.6234 -82.1676 # } ``` -------------------------------- ### Download and Join County Shapefiles Source: https://wpinvestigative.github.io/arcos/articles/county-analysis.html Downloads US Census shapefiles for counties in a specified state using the `tigris` package and joins this spatial data with the ARCOS prescription data. This prepares the data for mapping. ```r ## Set the option for shapefiles to load with sf options(tigris_class = "sf") ## Function to download county shapefiles in West Virginia wv_shape <- counties(state="WV", cb=T) ## Join the county dosage data we pulled wv <- left_join(wv, wv_shape, by=c("countyfips"="GEOID")) ``` -------------------------------- ### Call total_distributors_county function Source: https://wpinvestigative.github.io/arcos/reference/total_distributors_county.html Demonstrates how to call the `total_distributors_county` function with specified county, state, and API key. This is useful for fetching raw distribution data for a particular region. ```r total_distributors_county(county = "Mingo", state = "WV", key = "WaPo") ``` -------------------------------- ### Get Drug List Source: https://wpinvestigative.github.io/arcos/reference/drug_list.html Retrieves a list of all drugs available in the ARCOS database. Requires an API key for successful query. ```r drug_list(key = "WaPo") ``` ```r # \donttest{ library(arcos) np <- drug_list(key="WaPo") np #> ``` -------------------------------- ### Get Reporter Addresses by County and State Source: https://wpinvestigative.github.io/arcos/reference/reporter_addresses.html Fetches DEA designated addresses for reporters within a specified county and state. Requires an API key for the query. ```r reporter_addresses(county = "Mingo", state = "WV", key = "WaPo") ``` ```r # \donttest{ library(arcos) mingo_wv <- reporter_addresses(county = "Harris", state="TX", key="WaPo") head(mingo_wv) ``` -------------------------------- ### buyer_details Source: https://wpinvestigative.github.io/arcos/reference/buyer_details.html Fetches monthly summarized pill totals for a specific county within a state. Requires an API key for authentication. ```APIDOC ## buyer_details ### Description Retrieves monthly summarized pill totals for a specific county within a given state. This function requires an API key to be provided for successful query execution. ### Arguments * **county** (string) - Required - Filter the data to only this county (e.g. 'Mingo'). * **state** (string) - Required - Filter the data to county within this state (e.g. 'WV'). * **key** (string) - Required - Key needed to make query successful. ### Examples ```R # Load the library library(arcos) # Fetch data for Mingo county, WV mingo_wv <- buyer_details(county = "Mingo", state="WV", key="WaPo") # Display the first few rows of the result head(mingo_wv) ``` ``` -------------------------------- ### Get County Population Data Source: https://wpinvestigative.github.io/arcos/articles/per-capita-pharmacies.html Fetches population data for counties within a specified state using the `county_population` function. The `kable` function is used to display the head of the resulting data frame. ```r population <- county_population(state="WV", key="WaPo") kable(head(population)) ``` -------------------------------- ### Create Interactive Map with Leaflet Source: https://wpinvestigative.github.io/arcos/articles/individual-drug-mapping.html Generates an interactive map displaying methadone treatment facilities and pharmacies. Uses CartoDB.DarkMatter tiles, sets the view, and adds circle markers with popups and a legend. ```r m <- leaflet(buyers) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>% setView(-71.091112, 42.338827, zoom = 12) %>% addCircleMarkers(~lon, ~lat, popup=paste0(buyers$BUYER_NAME, "
", buyers$total, " total methadone"), weight = 3, radius=sqrt(buyers$total)/30, color=~cof(type), stroke = FALSE, fillOpacity = 0.3)%>% addLegend("bottomright", colors= c("#ffa500", "#13ED3F"), labels=c("Detox", "Pharmacy"), title="Buyer type") m ``` -------------------------------- ### Prepare Data for Mapping Source: https://wpinvestigative.github.io/arcos/articles/individual-drug-mapping.html Filters out any entries without longitude data, arranges the dataframe by total methadone amount in descending order, and sets up color factors for different buyer types. ```r buyers <- buyers %>% filter(!is.na(lon)) buyers <- buyers %>% arrange(desc(total)) cof <- colorFactor(c("#ffa500", "#13ED3F"), domain=c("PHARMACY", "DETOX/MAINTENANCE")) ``` -------------------------------- ### raw_data() Source: https://wpinvestigative.github.io/arcos/reference/index.html Provides access to raw ARCOS data. Warning: This is a very large file (130+ GB) and may not fit into memory. A download link is available if interested. ```APIDOC ## raw_data() ### Description Raw ARCOS data (Warning 130+ GB file) Warning: May not fit on your memory.. If interested in the raw data, you can download via the link below. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### buyer_details() Source: https://wpinvestigative.github.io/arcos/reference/index.html Retrieves monthly summarized pill totals aggregated by county. ```APIDOC ## buyer_details() ### Description Get monthly summarized pill totals by county. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### Get Total Pharmacies by State Source: https://wpinvestigative.github.io/arcos/articles/per-capita-pharmacies.html Retrieves a list of all pharmacies within a specified state, along with their total oxycodone and hydrocodone pill orders. The `kable` function is used to display the head of the resulting data frame. ```r west_virginia <- total_pharmacies_state(state="WV", key="WaPo") kable(head(west_virginia)) ``` -------------------------------- ### Call pharm_counties function Source: https://wpinvestigative.github.io/arcos/reference/pharm_counties.html Demonstrates how to call the `pharm_counties` function with specified county, state, and API key. This is the primary way to initiate a query for pharmacy county data. ```r pharm_counties(county = "Mingo", state = "WV", key = "WaPo") ``` -------------------------------- ### county_raw() Source: https://wpinvestigative.github.io/arcos/reference/index.html Downloads raw prescription data for a specified county into R, identified by state and county names. ```APIDOC ## county_raw() ### Description Download raw prescription data for specified county (by state and county names) into R. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### Call combined_buyer_monthly function Source: https://wpinvestigative.github.io/arcos/reference/combined_buyer_monthly.html This snippet shows how to call the `combined_buyer_monthly` function with specific county, state, year, and key parameters. It's used to initiate the data retrieval process. ```r combined_buyer_monthly( county = "Mingo", state = "WV", year = 2012, key = "WaPo" ) ``` -------------------------------- ### Retrieve and Inspect County Data Source: https://wpinvestigative.github.io/arcos/reference/county_list.html Shows how to call the `county_list` function and then display the first few rows of the resulting dataframe. Ensure the 'arcos' library is loaded before use. ```r # \donttest{ library(arcos) counties <- county_list(key="WaPo") head(counties) # > BUYER_COUNTY BUYER_STATE countyfips # > 1 AUTAUGA AL 01001 # > 2 BALDWIN AL 01003 # > 3 BARBOUR AL 01005 # > 4 BIBB AL 01007 # > 5 BLOUNT AL 01009 # > 6 BULLOCK AL 01011 # } ``` -------------------------------- ### pharmacy_raw() Source: https://wpinvestigative.github.io/arcos/reference/index.html Downloads raw prescription data for a specified pharmacy, identified by BUYER_DEA_NO, into R. ```APIDOC ## pharmacy_raw() ### Description Download raw prescription data for specified pharmacy (by BUYER_DEA_NO) into R. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### Call buyer_addresses Function Source: https://wpinvestigative.github.io/arcos/reference/buyer_addresses.html This snippet demonstrates how to call the `buyer_addresses` function with specified county, state, and API key. It's used to fetch pharmacy address data. ```r buyer_addresses(county = "Mingo", state = "WV", key = "WaPo") ``` -------------------------------- ### Call summarized_county_monthly function Source: https://wpinvestigative.github.io/arcos/reference/summarized_county_monthly.html Demonstrates a basic call to the summarized_county_monthly function with specified county, state, and API key. ```r summarized_county_monthly(county = "Mingo", state = "WV", key = "WaPo") ``` -------------------------------- ### drug_county_biz() Source: https://wpinvestigative.github.io/arcos/reference/index.html Downloads raw prescription data for individual drugs and business types, aggregated by county, into R. ```APIDOC ## drug_county_biz() ### Description Download raw prescription data for individual drugs and business type by county into R. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### Download Drug Prescription Data by County Source: https://wpinvestigative.github.io/arcos/reference/drug_county_biz.html Use the `drug_county_biz` function to download prescription data for a specific drug, county, state, and business type. Requires an API key. ```r drug_county_biz( drug = "Fentanyl", county = "Laurens", state = "GA", buyer_bus_act = "CHAIN PHARMACY", key = "WaPo" ) ``` -------------------------------- ### combined_buyer_monthly Source: https://wpinvestigative.github.io/arcos/reference/combined_buyer_monthly.html Fetches annual total pills for each buyer (pharmacy, etc.) in a specified county and state for a given year. Requires an API key for authentication. ```APIDOC ## combined_buyer_monthly ### Description Retrieves the annual total number of pills dispensed by each buyer (e.g., pharmacy) within a specific county and state for a given year. This function is useful for analyzing drug dispensing patterns at a granular level. ### Arguments * **county** (string) - Required - Filters the data to include only the specified county (e.g., 'Mingo'). * **state** (string) - Required - Filters the data to include only the specified state (e.g., 'WV'). * **year** (integer) - Required - Filters the data to the specified year (e.g., 2012). * **key** (string) - Required - An API key necessary to authenticate and successfully make the query. ### Example ```R library(arcos) mingo_wv <- combined_buyer_monthly(county = "Mingo", state="WV", year=2012, key="WaPo") head(mingo_wv) ``` ### See Also * [Washington Post DEA Pain Pill Database Resources](https://www.washingtonpost.com/graphics/2019/investigations/dea-pain-pill-database/#download-resources) * Other summarized functions: `buyer_details()`, `combined_buyer_annual()`, `summarized_county_annual()`, `summarized_county_monthly()`, `total_distributors_county()`, `total_distributors_state()`, `total_manufacturers_county()`, `total_manufacturers_state()`, `total_pharmacies_county()`, `total_pharmacies_state()` ``` -------------------------------- ### state_population Source: https://wpinvestigative.github.io/arcos/reference/state_population.html Fetches annual population data for a given state between 2006 and 2014. Requires a valid API key. ```APIDOC ## Function: state_population ### Description Retrieves annual population data for a specified state within the years 2006 to 2014. This function is useful for demographic analysis and historical population tracking. ### Arguments * **state** (string) - Required - The identifier for the state for which to retrieve population data (e.g., 'WV'). * **key** (string) - Required - An API key necessary to authenticate the request and ensure successful data retrieval. ### Example ```R # Load the arcos library library(arcos) # Get population data for West Virginia wv_population <- state_population(state = "WV", key = "WaPo") # Display the first few rows of the data head(wv_population) ``` ### Response Example ``` BUYER_STATE year population 1 WV 2009 1811403 2 WV 2010 1840802 3 WV 2011 1846372 4 WV 2012 1850481 5 WV 2006 1827912 6 WV 2007 1834052 ``` ``` -------------------------------- ### Manually Geolocation Detox/Maintenance Facilities Source: https://wpinvestigative.github.io/arcos/articles/individual-drug-mapping.html Creates a dataframe with manually entered latitude and longitude for detox and maintenance facilities using tribble. ```r detox <- tribble( ~BUYER_DEA_NO, ~lat, ~lon, "PV0130562", 42.366429, -71.058752, "PA0203024", 42.327501, -71.083288, "RB0192574", 42.363672, -71.05972, "RC0304395", 42.319285, -71.052785, "RH0102549", 42.333502, -71.066541, "RH0345783", 42.333502, -71.066541, "RC0252558", 42.333435, -71.073025, "RB0307480", 42.334507, -71.0741, "RC0441751", 42.300033, -71.101911, "RD0284581", 42.319239, -71.096921, "RR0198336", 42.300033, -71.101911, "RC0463327", 42.333138, -71.070542 ) ``` -------------------------------- ### Download Raw Pharmacy Data Source: https://wpinvestigative.github.io/arcos/reference/pharmacy_raw.html Call the pharmacy_raw function with the BUYER_DEA_NO and API key to download data for a specific pharmacy. Ensure you have the necessary key for the query. ```r pharmacy_raw(buyer_dea_no = "AB0454176", key = "WaPo") ``` -------------------------------- ### Call total_manufacturers_state function Source: https://wpinvestigative.github.io/arcos/reference/total_manufacturers_state.html This snippet shows how to call the `total_manufacturers_state` function with a state and API key. It is used to initiate the data retrieval process. ```r total_manufacturers_state(state = "WV", key = "WaPo") ``` -------------------------------- ### Join Pharmacy Data with Population Data Source: https://wpinvestigative.github.io/arcos/articles/per-capita-pharmacies.html Merges pharmacy dispensing data with county population data using a left join. This step is crucial for subsequent per capita calculations. ```r wv_joined <- left_join(west_virginia, population) #> Joining with `by = join_by(buyer_state, buyer_county)` kable(head(wv_joined)) ``` -------------------------------- ### Download Raw Data for a Specific County Source: https://wpinvestigative.github.io/arcos/reference/county_raw_fips.html Use this function to download raw prescription data for a single county. Ensure you have a valid API key and the correct FIPS code for the desired county. ```r county_raw_fips(fips = "01001", key = "WaPo") ``` -------------------------------- ### Basic Usage of county_list Source: https://wpinvestigative.github.io/arcos/reference/county_list.html Demonstrates the basic call to the `county_list` function with the required API key. This function retrieves a dataframe containing county names, state abbreviations, and FIPS codes. ```r county_list(key = "WaPo") ``` -------------------------------- ### Format Pharmacy Data Table Source: https://wpinvestigative.github.io/arcos/articles/per-capita-pharmacies.html Formats a data frame to display pharmacy information, applying specific formatting to columns like 'Pharmacy', 'Pills', and 'Pills per person'. Use this to create a visually appealing and informative table. ```r wv_joined %> formattable(align=c("l", "l", "l", "r", "r", "r"), list(Pharmacy = formatter("span", style = ~ style(color="grey", font.weight = "bold")), Pills=color_tile(customGreen0, customGreen), `Pills per person` = normalize_bar(customRed) )) ``` ``` -------------------------------- ### drug_fips_biz() Source: https://wpinvestigative.github.io/arcos/reference/index.html Downloads raw prescription data for individual drugs and business types, aggregated by county FIPS code, into R. ```APIDOC ## drug_fips_biz() ### Description Download raw prescription data for individual drugs and business type by county FIPS code into R. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### county_raw_fips() Source: https://wpinvestigative.github.io/arcos/reference/index.html Downloads raw prescription data for a specified county into R, identified by county FIPS code. ```APIDOC ## county_raw_fips() ### Description Download raw prescription data for specified county (by county FIPS code) into R. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### Download Drug Prescription Data by FIPS Source: https://wpinvestigative.github.io/arcos/reference/drug_fips_biz.html Use this function to download prescription data for a specific drug, county FIPS code, and business activity type. Requires an API key. ```r drug_fips_biz( drug = "Fentanyl", fips = "01001", buyer_bus_act = "CHAIN PHARMACY", key = "WaPo" ) ``` -------------------------------- ### Find Pharmacies by County and State Source: https://wpinvestigative.github.io/arcos/articles/suspicious-order-detection.html Use this function to retrieve a list of pharmacies within a specified county and state. It requires a valid API key. ```r pharm <- buyer_addresses(county = "Seminole", state="FL", key="WaPo") glimpse(pharm) ``` -------------------------------- ### Download Raw Prescription Data for a County Source: https://wpinvestigative.github.io/arcos/reference/county_raw.html Use this function to download raw prescription data for a specific county within a given state. Requires an API key for successful queries. The data includes information from pharmacies and practitioners for Hydrocodone and Oxycodone. ```r county_raw(county = "Mingo", state = "WV", key = "WaPo") ``` -------------------------------- ### Load and Inspect Pharmacy Raw Data Source: https://wpinvestigative.github.io/arcos/reference/pharmacy_raw.html Loads raw pharmacy transaction data for a specific buyer DEA number and key. It then displays the first few rows of the resulting data frame for initial inspection. ```R library(arcos) solo_pharm <- pharmacy_raw(buyer_dea_no="AB0454176", key="WaPo") head(solo_pharm) ``` -------------------------------- ### Call total_pharmacies_county function Source: https://wpinvestigative.github.io/arcos/reference/total_pharmacies_county.html This snippet shows the basic usage of the `total_pharmacies_county` function, specifying the county, state, and API key. ```r total_pharmacies_county(county = "Mingo", state = "WV", key = "WaPo") ``` -------------------------------- ### state_population() Source: https://wpinvestigative.github.io/arcos/reference/index.html Retrieves annual population data for states covering the years 2006 to 2014. ```APIDOC ## state_population() ### Description Get annual population for states between 2006 and 2014. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### summarized_county_monthly() Source: https://wpinvestigative.github.io/arcos/reference/index.html Retrieves monthly summarized pill totals aggregated by county. ```APIDOC ## summarized_county_monthly() ### Description Get monthly summarized pill totals by county. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### county_population() Source: https://wpinvestigative.github.io/arcos/reference/index.html Retrieves annual population data for counties covering the years 2006 to 2014. ```APIDOC ## county_population() ### Description Get annual population for counties between 2006 and 2014. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A (Function call) ### Request Example N/A (Function call) ### Response N/A (Function call) ``` -------------------------------- ### Consolidate and Summarize Methadone Orders by Buyer Type Source: https://wpinvestigative.github.io/arcos/articles/individual-drug-mapping.html Cleans and consolidates buyer categories, then calculates the total amount of Methadone (in grams, converted to MME) ordered by each consolidated type. It filters for purchase orders (TRANSACTION_CODE == 'S'). The results are then arranged in descending order of total amount. ```R # Clean up and consolidate the categories methadone <- methadone %>% mutate(type=case_when( grepl("PHARMACY", BUYER_BUS_ACT) ~ "PHARMACY", grepl("DETOX", BUYER_BUS_ACT) ~ "DETOX/MAINTENANCE", grepl("MAINT", BUYER_BUS_ACT) ~ "DETOX/MAINTENANCE", grepl("-VA", BUYER_BUS_ACT) ~ "VA", grepl("CLINIC", BUYER_BUS_ACT) ~ "CLINIC", TRUE ~ BUYER_BUS_ACT )) # totals methadone_summary <- methadone %>% # focus only on purchase orders, which is transaction code S filter(TRANSACTION_CODE=="S") %>% group_by(type) %>% # calculate amount mutate(amount=CALC_BASE_WT_IN_GM*MME_Conversion_Factor) %>% summarize(total=sum(amount, na.rm=T)) %>% arrange(desc(total)) ```