Type: | Package |
Title: | Generator from American Community Survey Geodatabases |
Version: | 2.0.1 |
Description: | The American Community Survey (ACS) https://www.census.gov/programs-surveys/acs offers geodatabases with geographic information and associated data of interest to researchers in the area. The goal of this package is to generate objects that allow us to access and consult the information available in various formats, such as in 'GeoPackage' format or in multidimensional 'ROLAP' (Relational On-Line Analytical Processing) star format. |
License: | MIT + file LICENSE |
URL: | https://josesamos.github.io/geogenr/, https://github.com/josesamos/geogenr |
BugReports: | https://github.com/josesamos/geogenr/issues |
Depends: | R (≥ 2.10) |
Imports: | dplyr, geomultistar, httr, readr, rolap, sf, stats, stringr, tibble, tidyr, tidyselect, utils |
Suggests: | DBI, dbplyr, DiagrammeR, DiagrammeRsvg, dm, knitr, pander, rmarkdown, RSQLite, snakecase, testthat (≥ 3.0.0) |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
Language: | en-GB |
LazyData: | true |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2024-01-08 19:34:51 UTC; joses |
Author: | Jose Samos |
Maintainer: | Jose Samos <jsamos@ugr.es> |
Repository: | CRAN |
Date/Publication: | 2024-01-09 01:20:03 UTC |
acs_5yr
S3 class
Description
An acs_5yr
object is created from a given local dir. This dir will contain
the geodatabase files that we download.
Usage
acs_5yr(dir = "")
Arguments
dir |
A string. |
Value
An acs_5yr
object.
See Also
Other data download functions:
download_selected_files()
,
get_area_file_names()
,
get_area_groups()
,
get_area_years()
,
get_areas()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir = dir)
Titles and Years of Selected Demographic and Economic Data
Description
Available selected Demographic and Economic Data from the American Community Survey (ACS) 5-year estimates data titles and years.
Usage
acs_5yr_md
Format
A vector list.
Source
"Alaska Native Regional Corporation", 2021, "X01 Age And Sex"
Description
Topic selected for the area and years indicated: "Alaska Native Regional Corporation", 2021.
Usage
anrc_2021_x01
Format
An acs_5yr_topic
object.
Examples
# Defined by:
dir <- tempdir()
source_dir <- system.file("extdata/acs_5yr", package = "geogenr")
files <- list.files(source_dir, "*.zip", full.names = TRUE)
file.copy(from = files, to = dir, overwrite = TRUE)
ac <- acs_5yr(dir)
files <- ac |>
unzip_files()
anrc_2021_x01 <- ac |>
as_acs_5yr_topic("Alaska Native Regional Corporation",
2021,
"X01 Age And Sex")
Save as GeoPackage
Description
Save the data layer (geographic information layer), the metadata layer and the
data source description layer in a file in GeoPackage
format to be able to
work with other tools.
Usage
as_GeoPackage(geo, dir, name)
## S3 method for class 'acs_5yr_geo'
as_GeoPackage(geo, dir = NULL, name = NULL)
Arguments
geo |
An |
dir |
A string. |
name |
A string, file name. |
Details
The GeoPackage
format only allows defining a maximum of 1998 columns. If the
number of variables and columns in the geographic layer exceeds this number,
it cannot be saved in this format.
Value
A string, file name.
See Also
Other data exploitation and export functions:
as_acs_5yr_geo()
,
as_flat_table()
,
as_geomultistar()
,
as_star_database()
,
get_metadata()
,
set_metadata()
Examples
act <- anrc_2021_x01 |>
select_report(report = "B01002-Median Age By Sex")
geo <- act |>
as_acs_5yr_geo()
dir <- tempdir()
file <- geo |>
as_GeoPackage(dir)
Get an acs_5yr_geo
object
Description
Once we have selected the topics that interest us and, possibly also the reports
or subreports, we obtain an acs_5yr_geo
object with which we can represent
or export the geographic layer along with the data of interest more easily.
Usage
as_acs_5yr_geo(act)
## S3 method for class 'acs_5yr_topic'
as_acs_5yr_geo(act)
Arguments
act |
An |
Value
An acs_5yr_geo
object.
See Also
Other data exploitation and export functions:
as_GeoPackage()
,
as_flat_table()
,
as_geomultistar()
,
as_star_database()
,
get_metadata()
,
set_metadata()
Examples
act <- anrc_2021_x01 |>
select_report(report = "B01002-Median Age By Sex")
geo <- act |>
as_acs_5yr_geo()
As ACS census topic (report group)
Description
Gets an ACS census topic object (report group) for the given years of the Demographic and Economic Areas that are downloaded and unzipped, available to be queried.
Usage
as_acs_5yr_topic(ac, area, years, topic)
## S3 method for class 'acs_5yr'
as_acs_5yr_topic(ac, area, years = NULL, topic = NULL)
Arguments
ac |
An |
area |
A string, area name. |
years |
A vector, year number. |
topic |
A vector, topic name. |
Details
If no year is indicated, all available years are taken. If no topic is given, the first one that appears in the files is taken.
Value
An acs_5yr_topic
object.
See Also
Other data selection functions:
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
dir <- tempdir()
source_dir <- system.file("extdata/acs_5yr", package = "geogenr")
files <- list.files(source_dir, "*.zip", full.names = TRUE)
file.copy(from = files, to = dir, overwrite = TRUE)
ac <- acs_5yr(dir)
files <- ac |>
unzip_files()
anrc_2021_x01 <- ac |>
as_acs_5yr_topic("Alaska Native Regional Corporation",
2021,
"X01 Age And Sex")
anrc_2021_2022_x01_x07 <- ac |>
as_acs_5yr_topic("Alaska Native Regional Corporation",
topic = c("X01 Age And Sex", "X07 Migration"))
As rolap::flat_table
object
Description
Obtain an rolap::flat_table
object to be able to modify the data or integrate
it with other data.
Usage
as_flat_table(act, attributes)
## S3 method for class 'acs_5yr_topic'
as_flat_table(act, attributes = NULL)
Arguments
act |
An |
attributes |
A string vector. |
Details
We can indicate the attributes of the geographic layer to include in the export. Otherwise, the default attributes are included (not area, perimeter or location attributes).
Value
A flat_table
object.
See Also
Other data exploitation and export functions:
as_GeoPackage()
,
as_acs_5yr_geo()
,
as_geomultistar()
,
as_star_database()
,
get_metadata()
,
set_metadata()
Examples
ft <- anrc_2021_x01 |>
as_flat_table()
As geomultistar::geomultistar
object
Description
Obtain an geomultistar::geomultistar
object to be able to enrich multidimensional
queries with geographic data.
Usage
as_geomultistar(act, attributes)
## S3 method for class 'acs_5yr_topic'
as_geomultistar(act, attributes = NULL)
Arguments
act |
An |
attributes |
A string vector. |
Details
We can indicate the attributes of the geographic layer to include in the export. Otherwise, the default attributes are included (not area, perimeter or location attributes).
Value
A geomultistar
object.
See Also
Other data exploitation and export functions:
as_GeoPackage()
,
as_acs_5yr_geo()
,
as_flat_table()
,
as_star_database()
,
get_metadata()
,
set_metadata()
Examples
gms <- anrc_2021_x01 |>
as_geomultistar()
As rolap::star_database
object
Description
Obtain an rolap::star_database
object to be able to export it to a RDBMS and
make queries with other tools.
Usage
as_star_database(act, attributes)
## S3 method for class 'acs_5yr_topic'
as_star_database(act, attributes = NULL)
Arguments
act |
An |
attributes |
A string vector. |
Details
We can indicate the attributes of the geographic layer to include in the export. Otherwise, the default attributes are included (not area, perimeter or location attributes).
Value
A star_database
object.
See Also
Other data exploitation and export functions:
as_GeoPackage()
,
as_acs_5yr_geo()
,
as_flat_table()
,
as_geomultistar()
,
get_metadata()
,
set_metadata()
Examples
st <- anrc_2021_x01 |>
as_star_database()
Download selected files
Description
Download the files that have been selected and have not been downloaded yet, unzip them (if desired) and, if everything went well and is indicated in the parameter, delete the downloaded files.
Usage
download_selected_files(ac, subdir = NULL, unzip = TRUE, delete_zip = FALSE)
Arguments
ac |
An |
subdir |
NULL/'year'/'area', output subdir. |
unzip |
A boolean, unzip files. |
delete_zip |
A boolean, delete zip files if correctly unzipped. |
Details
In the subdir
parameter, the values NULL, 'year' or 'area' can be indicated.
With NULL it does not create any subdirs, with 'year' it creates them by years
of downloaded files and with 'area' it creates them by areas.
Value
A vector, files correctly obtained.
See Also
Other data download functions:
acs_5yr()
,
get_area_file_names()
,
get_area_groups()
,
get_area_years()
,
get_areas()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
ac <- ac |>
select_area_files("Alaska Native Regional Corporation", 2020:2021)
files <- ac |>
download_selected_files(unzip = FALSE)
Get area file names
Description
Get area url file names for the given years. If no year is indicated, all available ones are obtained.
Usage
get_area_file_names(ac, area, years)
## S3 method for class 'acs_5yr'
get_area_file_names(ac, area, years = NULL)
Arguments
ac |
An |
area |
A string, area name. |
years |
A vector, year number. |
Value
A vector, file urls.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_groups()
,
get_area_years()
,
get_areas()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
url <- ac |>
get_area_file_names("State", 2019:2021)
url <- ac |>
get_area_file_names("State")
Get area groups
Description
Gets the names of the Demographic and Economic Area Groups where data is available.
Usage
get_area_groups(ac)
## S3 method for class 'acs_5yr'
get_area_groups(ac)
Arguments
ac |
An |
Value
A vector, area group names.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_file_names()
,
get_area_years()
,
get_areas()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
groups <- ac |>
get_area_groups()
Get available area years
Description
Get the years for which data has been found to be available for an area.
Usage
get_area_years(ac, area)
## S3 method for class 'acs_5yr'
get_area_years(ac, area)
Arguments
ac |
An |
area |
A string, area name. |
Value
A vector, area years.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_file_names()
,
get_area_groups()
,
get_areas()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
years <- ac |>
get_area_years(area = "State")
Get area names of a group
Description
Gets the names of the Demographic and Economic Areas of a group or set of groups.
Usage
get_areas(ac, group)
## S3 method for class 'acs_5yr'
get_areas(ac, group = NULL)
Arguments
ac |
An |
group |
A string, area group name. |
Details
If no group is indicated, all available areas are obtained.
Value
A vector, area names.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_file_names()
,
get_area_groups()
,
get_area_years()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
areas <- ac |>
get_areas(group = "Statistical Areas")
Get available area topics (report groups)
Description
Gets the topics (report groups) for the given years of the Demographic and Economic Areas that are downloaded and unzipped, available to be queried.
Usage
get_available_area_topics(ac, area, years)
## S3 method for class 'acs_5yr'
get_available_area_topics(ac, area, years = NULL)
Arguments
ac |
An |
area |
A string, area name. |
years |
A vector, year number. |
Value
A vector, available report groups.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
dir <- tempdir()
source_dir <- system.file("extdata/acs_5yr", package = "geogenr")
files <- list.files(source_dir, "*.zip", full.names = TRUE)
file.copy(from = files, to = dir, overwrite = TRUE)
ac <- acs_5yr(dir)
files <- ac |>
unzip_files()
topics <- ac |>
get_available_area_topics("Alaska Native Regional Corporation",
2021)
topics <- ac |>
get_available_area_topics("Alaska Native Regional Corporation")
Get available area years
Description
Gets the years of the Demographic and Economic Areas that are downloaded and unzipped, available to be queried.
Usage
get_available_area_years(ac, area)
## S3 method for class 'acs_5yr'
get_available_area_years(ac, area)
Arguments
ac |
An |
area |
A string, area name. |
Value
A vector, area years.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
dir <- tempdir()
source_dir <- system.file("extdata/acs_5yr", package = "geogenr")
files <- list.files(source_dir, "*.zip", full.names = TRUE)
file.copy(from = files, to = dir, overwrite = TRUE)
ac <- acs_5yr(dir)
files <- ac |>
unzip_files()
years <- ac |>
get_available_area_years(area = "Alaska Native Regional Corporation")
Get available area names
Description
Gets the names of the Demographic and Economic Areas that are downloaded and unzipped, available to be queried.
Usage
get_available_areas(ac)
## S3 method for class 'acs_5yr'
get_available_areas(ac)
Arguments
ac |
An |
Value
A vector, area names.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
dir <- tempdir()
source_dir <- system.file("extdata/acs_5yr", package = "geogenr")
files <- list.files(source_dir, "*.zip", full.names = TRUE)
file.copy(from = files, to = dir, overwrite = TRUE)
ac <- acs_5yr(dir)
files <- ac |>
unzip_files()
areas <- ac |>
get_available_areas()
Get code from area name
Description
Obtain the code that appears in the name of the file associated with the area.
Usage
get_code_from_area_name(ac, area)
## S3 method for class 'acs_5yr'
get_code_from_area_name(ac, area)
Arguments
ac |
An |
area |
A string, area name. |
Value
A vector, area code.
See Also
Other information functions:
get_name_from_area_code()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
code <- ac |>
get_code_from_area_name(area = "State")
Get file area (with year)
Description
Given a file, get the associated code (in the name), includes the year as the name of the vector elements..
Usage
get_file_area(file)
Arguments
file |
A string vector. |
Value
A string vector.
Get file year
Description
Given a file, get the associated year (in the name).
Usage
get_file_year(file)
Arguments
file |
A string vector. |
Value
A string vector.
Get gbd files
Description
Given a dir, we get the gbd files in it, at any level.
Usage
get_gbd_files(dir)
Arguments
dir |
A string. |
Value
A string vector.
Get geographical attributes
Description
Get the names of the geographic layer attributes (except for the geometry field).
Usage
get_geo_attribute_names(act)
## S3 method for class 'acs_5yr_topic'
get_geo_attribute_names(act)
Arguments
act |
An |
Value
A vector, geographical attribute names.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
names <- anrc_2021_x01 |>
get_geo_attribute_names()
Get geographic layer
Description
Get the geographic layer.
Usage
## S3 method for class 'acs_5yr_geo'
get_geo_layer(glc)
get_geo_layer(glc)
## S3 method for class 'acs_5yr_topic'
get_geo_layer(glc)
Arguments
glc |
An |
Value
A sf
object.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
layer <- anrc_2021_x01 |>
get_geo_layer()
Get geo layer
Description
Get geo layer
Usage
get_geo_layer_from_file(file)
Arguments
file |
A string, file name. |
Value
A st
, geo data.
Get layer data
Description
Get layer data
Usage
get_layer_data(layer, file)
Arguments
layer |
A string, layer name. |
file |
A string, file name. |
Value
A tibble
, layer data.
Get the metadata layer
Description
The metadata layer includes the names and description through various fields of the variables contained in the reports.
Usage
get_metadata(geo)
## S3 method for class 'acs_5yr_geo'
get_metadata(geo)
Arguments
geo |
An |
Details
The way to select the variables we want to work with is to filter this layer
and subsequently set it as the object's metadata layer using the set_metadata()
function.
Value
A tibble
object.
See Also
Other data exploitation and export functions:
as_GeoPackage()
,
as_acs_5yr_geo()
,
as_flat_table()
,
as_geomultistar()
,
as_star_database()
,
set_metadata()
Examples
act <- anrc_2021_x01 |>
select_report(report = "B01002-Median Age By Sex")
geo <- act |>
as_acs_5yr_geo()
metadata <- geo |>
get_metadata()
Get name from area code
Description
Get the name of the area from the code that appears in the name of the area files.
Usage
get_name_from_area_code(ac, area)
## S3 method for class 'acs_5yr'
get_name_from_area_code(ac, area)
Arguments
ac |
An |
area |
A string, area name. |
Value
A vector, area code.
See Also
Other information functions:
get_code_from_area_name()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
name <- ac |>
get_name_from_area_code(area = "METDIV")
Get names of other topics (report groups)
Description
The area that we have downloaded has a set of defined topics, we have selected one of them, this function shows us the rest of the available topics in the area.
Usage
get_names_of_other_topics(act)
## S3 method for class 'acs_5yr_topic'
get_names_of_other_topics(act)
Arguments
act |
An |
Value
A vector, available topics.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
topics <- anrc_2021_x01 |>
get_names_of_other_topics()
Get report names
Description
Each topic includes several reports. Once a topic has been selected, using this function we obtain the name of the available reports. The report code is included with the name. Each report can contain multiple subreports.
Usage
get_report_names(act)
## S3 method for class 'acs_5yr_topic'
get_report_names(act)
Arguments
act |
An |
Value
A vector, report names.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
reports <- anrc_2021_x01 |>
get_report_names()
Get selected file names
Description
Gets the names of the files selected to be downloaded.
Usage
get_selected_file_names(ac)
## S3 method for class 'acs_5yr'
get_selected_file_names(ac)
Arguments
ac |
An |
Value
A vector, file names.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_file_names()
,
get_area_groups()
,
get_area_years()
,
get_areas()
,
get_too_heavy_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
groups <- ac |>
get_selected_file_names()
Get subreport names
Description
Each topic includes several reports and subreports. Once a topic has been selected, using this function we obtain the name of the available subreports of a report. If no report is indicated, all subreports of the topic are obtained.
Usage
get_subreport_names(act, report)
## S3 method for class 'acs_5yr_topic'
get_subreport_names(act, report = NULL)
Arguments
act |
An |
report |
A string, report name. |
Value
A vector, subreport names.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
reports <- anrc_2021_x01 |>
get_subreport_names(report = "B01002-Median Age By Sex")
Get too heavy file names
Description
Gets the names of the files that are too heavy to be download with the available function. We have downloaded them directly with the web browser.
Usage
get_too_heavy_file_names(ac)
## S3 method for class 'acs_5yr'
get_too_heavy_file_names(ac)
Arguments
ac |
An |
Value
A vector, too heavy file names.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_file_names()
,
get_area_groups()
,
get_area_years()
,
get_areas()
,
get_selected_file_names()
,
select_area_files()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
groups <- ac |>
get_too_heavy_file_names()
Select topic (report group)
Description
Select the given topic with. If no topic is given, the first one that appears in the files is taken.
Usage
get_topic_data(act)
Arguments
act |
An |
Value
An acs_5yr_topic
object.
Get topic name (report groups)
Description
Get the selected topic by which this object has been defined.
Usage
get_topic_name(act)
## S3 method for class 'acs_5yr_topic'
get_topic_name(act)
Arguments
act |
An |
Details
A topic is made up of a set of reports.
Value
A vector, topic name.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
select_report()
,
select_subreport()
,
select_topic()
Examples
topic <- anrc_2021_x01 |>
get_topic_name()
Name to title
Description
Name to title
Usage
name_to_title(name)
Arguments
name |
A string. |
Value
A string
Name with nexus
Description
Given a name, if it ends in "/" the nexus is the empty string, otherwise it is "/". Add the nexus.
Usage
name_with_nexus(name)
Arguments
name |
A string. |
Value
A string.
New acs_5yr_topic object
Description
New acs_5yr_topic object
Usage
new_acs_5yr_topic(ac, area, years = NULL, topic = NULL)
Arguments
ac |
An |
area |
A string, area name. |
years |
A vector, year number. |
topic |
A string, topic name. |
Value
An acs_5yr_topic
object.
Select area files
Description
Select area files for the given years. If no year is indicated, all available ones are selected.
Usage
select_area_files(ac, area, years)
## S3 method for class 'acs_5yr'
select_area_files(ac, area, years = NULL)
Arguments
ac |
An |
area |
A string, area name. |
years |
A vector, year number. |
Value
An acs_5yr
object.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_file_names()
,
get_area_groups()
,
get_area_years()
,
get_areas()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
unzip_files()
Examples
dir <- system.file("extdata/acs_5yr", package = "geogenr")
ac <- acs_5yr(dir)
ac <- ac |>
select_area_files("State", 2019:2021)
ac <- ac |>
select_area_files("State")
Select report
Description
Select the reports whose names are indicated. We reduce the available reports and variables to those of the selected reports.
Usage
select_report(act, report)
## S3 method for class 'acs_5yr_topic'
select_report(act, report = NULL)
Arguments
act |
An |
report |
A string vector, report names. |
Value
An acs_5yr_topic
object.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_subreport()
,
select_topic()
Examples
act <- anrc_2021_x01 |>
select_report(report = "B01002-Median Age By Sex")
Select subreport
Description
Select the subreports whose names are indicated. We reduce the available subreports and variables to those of the selected subreports.
Usage
select_subreport(act, subreport)
## S3 method for class 'acs_5yr_topic'
select_subreport(act, subreport = NULL)
Arguments
act |
An |
subreport |
A string vector, subreport names. |
Value
A vector, topic name.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_topic()
Examples
act2 <- anrc_2021_x01 |>
select_subreport(
c(
"B01002-B-Median Age By Sex (Black Or African American Alone)",
"B01002-C-Median Age By Sex (American Indian And Alaska Native Alone)"
)
)
Select topic (report group)
Description
Select a topic. If no topic is given, the first one that appears in the area is taken.
Usage
select_topic(act, topic)
## S3 method for class 'acs_5yr_topic'
select_topic(act, topic = NULL)
Arguments
act |
An |
topic |
A string, topic name. |
Value
An acs_5yr_topic
object.
See Also
Other data selection functions:
as_acs_5yr_topic()
,
get_available_area_topics()
,
get_available_area_years()
,
get_available_areas()
,
get_geo_attribute_names()
,
get_geo_layer.acs_5yr_geo()
,
get_names_of_other_topics()
,
get_report_names()
,
get_subreport_names()
,
get_topic_name()
,
select_report()
,
select_subreport()
Examples
dir <- tempdir()
source_dir <- system.file("extdata/acs_5yr", package = "geogenr")
files <- list.files(source_dir, "*.zip", full.names = TRUE)
file.copy(from = files, to = dir, overwrite = TRUE)
ac <- acs_5yr(dir)
files <- ac |>
unzip_files()
act <- ac |>
as_acs_5yr_topic("Alaska Native Regional Corporation",
2021,
"X01 Age And Sex")
act <- act |>
select_topic(topic = "X03 Hispanic Or Latino Origin")
Set metadata layer
Description
The metadata layer includes the names and description through various fields of the variables contained in the reports.
Usage
set_metadata(geo, metadata)
## S3 method for class 'acs_5yr_geo'
set_metadata(geo, metadata)
Arguments
geo |
An |
metadata |
A |
Details
When we set the metadata layer, after filtering it, the data layer is also filtered keeping only the variables from the metadata layer.
Value
A sf
object.
See Also
Other data exploitation and export functions:
as_GeoPackage()
,
as_acs_5yr_geo()
,
as_flat_table()
,
as_geomultistar()
,
as_star_database()
,
get_metadata()
Examples
act <- anrc_2021_x01 |>
select_report(report = "B01002-Median Age By Sex")
geo <- act |>
as_acs_5yr_geo()
metadata <- geo |>
get_metadata()
metadata <- dplyr::filter(metadata, item2 == "Female")
geo2 <- geo |>
set_metadata(metadata)
Transform layer according to metadata
Description
Transform layer according to metadata
Usage
transform_layer(layer, metadata)
Arguments
layer |
A |
metadata |
A |
Value
A vector
Transform metadata layer
Description
Transform metadata layer
Usage
transform_metadata_basic(metadata)
Arguments
metadata |
A vector |
Value
A vector
Transform metadata layer
Description
Transform metadata layer
Usage
transform_metadata_rest(metadata)
Arguments
metadata |
A vector |
Value
A vector
Unzip files
Description
Unzip files that are not already unzipped in the object and, if everything went well and is indicated in the parameter, delete the unzipped files.
Usage
unzip_files(ac, subdir = NULL, delete_zip = FALSE)
Arguments
ac |
An |
subdir |
NULL/'year'/'area', output subdir. |
delete_zip |
A boolean, delete zip files if correctly unzipped. |
Details
In the subdir
parameter, the values NULL, 'year' or 'area' can be indicated.
With NULL it does not create any subdirs, with 'year' it creates them by years
of files and with 'area' it creates them by areas.
Value
A vector of strings, name of the processed files.
See Also
Other data download functions:
acs_5yr()
,
download_selected_files()
,
get_area_file_names()
,
get_area_groups()
,
get_area_years()
,
get_areas()
,
get_selected_file_names()
,
get_too_heavy_file_names()
,
select_area_files()
Examples
dir <- tempdir()
source_dir <- system.file("extdata/acs_5yr", package = "geogenr")
files <- list.files(source_dir, "*.zip", full.names = TRUE)
file.copy(from = files, to = dir, overwrite = TRUE)
ac <- acs_5yr(dir)
files <- ac |>
unzip_files()
url_file_exists
Description
https://stackoverflow.com/questions/60318926/how-to-check-if-file-exists-in-the-url-before-use-download-file-in-r
Usage
url_file_exists(url)
Arguments
url |
A string. |
Value
A boolean
Validate names
Description
Validate names
Usage
validate_names(defined_names, names, concept = "name", repeated = FALSE)
Arguments
defined_names |
A vector of strings, defined attribute names. |
names |
A vector of strings, new attribute names. |
concept |
A string, treated concept. |
repeated |
A boolean, repeated names allowed. |
Value
A vector of strings, names.