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

Star01 #3

Merged
merged 38 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a380562
previous functions (WIP)
josesamos Oct 30, 2023
d1fbdf0
download and unzip (WIP)
josesamos Oct 31, 2023
22f66fc
donwload local (WIP)
josesamos Oct 31, 2023
ee9767f
Delete metadata and reorganice files
josesamos Oct 31, 2023
ab6cf9c
functions reorganization (WIP)
josesamos Oct 31, 2023
510558d
add years to dedata
josesamos Oct 31, 2023
8b8a1ba
dedata download problems
josesamos Oct 31, 2023
d1da664
folder class (WIP)
josesamos Nov 1, 2023
fad796f
census class definition (WIP)
josesamos Nov 1, 2023
190f3f9
As census topic class ini
josesamos Nov 1, 2023
c32801a
function reorganization in files
josesamos Nov 1, 2023
f241a56
delete old tests
josesamos Nov 1, 2023
f971923
check project (move files to data)
josesamos Nov 1, 2023
02a1880
examples problem (WIP)
josesamos Nov 1, 2023
758fa89
rename classes and tests
josesamos Nov 2, 2023
ddf99dd
get codes and names
josesamos Nov 2, 2023
85589d5
topics (WIP)
josesamos Nov 2, 2023
2aa725f
select topic
josesamos Nov 2, 2023
b450f7c
load layer tables
josesamos Nov 2, 2023
360f631
first column year (WIP)
josesamos Nov 2, 2023
fd9c3cf
layer components selection
josesamos Nov 2, 2023
b69d7fb
simple metadata (WIP)
josesamos Nov 3, 2023
9bc4cc3
select reports (WIP)
josesamos Nov 3, 2023
66cf9ee
as acs geo (WIP)
josesamos Nov 4, 2023
6daf79a
rolap (WIP)
josesamos Nov 4, 2023
fb352cd
as rolap (WIP)
josesamos Nov 4, 2023
df0d6ef
fix (WIP)
josesamos Nov 4, 2023
76ee126
review and test (WIP)
josesamos Nov 4, 2023
74585ce
new data definition
josesamos Nov 4, 2023
73f3e5f
documentation and test (WIP)
josesamos Nov 5, 2023
64adfd3
export functions documentation and test
josesamos Nov 5, 2023
ad43366
readme and vignette
josesamos Nov 5, 2023
6521aa2
fix vignette requirements
josesamos Nov 5, 2023
43c1f5f
update news
josesamos Nov 5, 2023
b3d66fc
fix vignette
josesamos Nov 5, 2023
94b9c45
fix vignette
josesamos Nov 5, 2023
4885de7
fix documentation errors
josesamos Nov 5, 2023
edfce15
use DiagrammeRsvg in description
josesamos Nov 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
^docs$
^pkgdown$
^CRAN-SUBMISSION$
^datos$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.RData
.Rproj.user
docs
datos
inst/doc
29 changes: 17 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
Type: Package
Package: geogenr
Title: 'geomultistar' Object Generator from American Community Survey Geodatabases
Title: Generator from American Community Survey Geodatabases
Version: 1.0.1.9000
Authors@R:
person("Jose", "Samos", , "jsamos@ugr.es", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0002-4457-3439"))
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 'geomultistar'
<https://CRAN.R-project.org/package=geomultistar> objects from those
geodatabases automatically, once the focus of attention is selected.
Multidimensional queries with geographic information can be easily
defined on these objects.
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
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:
data.table,
dplyr,
geomultistar,
httr,
readr,
rolap,
sf,
snakecase,
starschemar,
stats,
stringr,
tibble,
tidyr,
tidyselect,
tm,
utils
Suggests:
DBI,
dbplyr,
DiagrammeR,
DiagrammeRsvg,
dm,
knitr,
pander,
rmarkdown,
testthat
RSQLite,
snakecase,
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-GB
LazyData: true
Expand Down
97 changes: 60 additions & 37 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
# Generated by roxygen2: do not edit by hand

S3method(delete_empty_columns,uscb_metadata)
S3method(download_geodatabases,uscb_acs_5ye)
S3method(get_available_years_downloaded,uscb_acs_5ye)
S3method(get_available_years_in_the_web,uscb_acs_5ye)
S3method(get_basic_flat_table,uscb_layer)
S3method(get_common_flat_table,uscb_folder)
S3method(get_common_geomultistar,uscb_folder)
S3method(get_field_values,uscb_metadata)
S3method(get_flat_table,uscb_layer)
S3method(get_geomultistar,uscb_layer)
S3method(get_layer,uscb_layer)
S3method(get_layer_group,uscb_layer)
S3method(get_layer_group_names,uscb_layer)
S3method(get_layer_names,uscb_layer)
S3method(get_legal_and_administrative_areas,uscb_acs_5ye)
S3method(get_metadata,uscb_metadata)
S3method(get_statistical_areas,uscb_acs_5ye)
S3method(interpret_metadata,uscb_metadata)
S3method(reformat_metadata,uscb_metadata)
S3method(show_fields,uscb_metadata)
export(download_geodatabases)
export(get_available_years_downloaded)
export(get_available_years_in_the_web)
export(get_common_flat_table)
export(get_common_geomultistar)
export(get_flat_table)
export(get_geomultistar)
export(get_layer)
export(get_layer_group)
export(get_layer_group_names)
export(get_layer_names)
export(get_legal_and_administrative_areas)
export(get_statistical_areas)
export(uscb_acs_5ye)
export(uscb_folder)
export(uscb_layer)
export(uscb_metadata)
S3method(as_GeoPackage,acs_5yr_geo)
S3method(as_acs_5yr_geo,acs_5yr_topic)
S3method(as_acs_5yr_topic,acs_5yr)
S3method(as_flat_table,acs_5yr_topic)
S3method(as_star_database,acs_5yr_topic)
S3method(get_area_file_names,acs_5yr)
S3method(get_area_groups,acs_5yr)
S3method(get_area_years,acs_5yr)
S3method(get_areas,acs_5yr)
S3method(get_available_area_topics,acs_5yr)
S3method(get_available_area_years,acs_5yr)
S3method(get_available_areas,acs_5yr)
S3method(get_code_from_area_name,acs_5yr)
S3method(get_geo_attribute_names,acs_5yr_topic)
S3method(get_geo_layer,acs_5yr_geo)
S3method(get_geo_layer,acs_5yr_topic)
S3method(get_metadata,acs_5yr_geo)
S3method(get_name_from_area_code,acs_5yr)
S3method(get_names_of_other_topics,acs_5yr_topic)
S3method(get_report_names,acs_5yr_topic)
S3method(get_selected_file_names,acs_5yr)
S3method(get_subreport_names,acs_5yr_topic)
S3method(get_too_heavy_file_names,acs_5yr)
S3method(get_topic_name,acs_5yr_topic)
S3method(select_area_files,acs_5yr)
S3method(select_report,acs_5yr_topic)
S3method(select_subreport,acs_5yr_topic)
S3method(select_topic,acs_5yr_topic)
S3method(set_metadata,acs_5yr_geo)
export(acs_5yr)
export(as_GeoPackage)
export(as_acs_5yr_geo)
export(as_acs_5yr_topic)
export(as_flat_table)
export(as_star_database)
export(download_selected_files)
export(get_area_file_names)
export(get_area_groups)
export(get_area_years)
export(get_areas)
export(get_available_area_topics)
export(get_available_area_years)
export(get_available_areas)
export(get_code_from_area_name)
export(get_geo_attribute_names)
export(get_geo_layer)
export(get_metadata)
export(get_name_from_area_code)
export(get_names_of_other_topics)
export(get_report_names)
export(get_selected_file_names)
export(get_subreport_names)
export(get_too_heavy_file_names)
export(get_topic_name)
export(select_area_files)
export(select_report)
export(select_subreport)
export(select_topic)
export(set_metadata)
export(unzip_files)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# geogenr (development version)
* New data model.
* Functions to consult, select and download the available information.
* Functions to select the available information to work with.
* Functions to filter and export data as a `GeoPackage`.
* Functions to export data as objects of the `rolap::flat_table` and
`rolap::star_database` classes.

# geogenr 1.0.1
* Update documentation and website.
Expand Down
134 changes: 134 additions & 0 deletions R/acs_5yr_common.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

#' Validate names
#'
#' @param defined_names A vector of strings, defined attribute names.
#' @param names A vector of strings, new attribute names.
#' @param concept A string, treated concept.
#' @param repeated A boolean, repeated names allowed.
#'
#' @return A vector of strings, names.
#'
#' @keywords internal
validate_names <- function(defined_names, names, concept = 'name', repeated = FALSE) {
if (is.null(names)) {
names <- defined_names
} else {
if (!repeated) {
stopifnot("There are repeated values." = length(names) == length(unique(names)))
}
for (name in names) {
if (!(name %in% defined_names)) {
stop(sprintf(
"'%s' is not defined as %s.",
name, concept

Check warning on line 23 in R/acs_5yr_common.R

View check run for this annotation

Codecov / codecov/patch

R/acs_5yr_common.R#L21-L23

Added lines #L21 - L23 were not covered by tests
))
}
}
}
names
}

#' Name with nexus
#'
#' Given a name, if it ends in "/" the nexus is the empty string, otherwise it
#' is "/". Add the nexus.
#'
#' @param name A string.
#'
#' @return A string.
#'
#' @keywords internal
name_with_nexus <- function(name) {
l <- nchar(name)
c <- substr(name, start = l, stop = l)
res <- name
for (i in seq_along(c)) {
if (c[i] != "/") {
res[i] <- paste0(name[i], "/")
}
}
res
}


#' Get gbd files
#'
#' Given a dir, we get the gbd files in it, at any level.
#'
#' @param dir A string.
#'
#' @return A string vector.
#'
#' @keywords internal
get_gbd_files <- function(dir) {
files <- list.files(path = dir, full.names = TRUE, recursive = TRUE, include.dirs = TRUE)
files <- files[dir.exists(files)]
n <- nchar(files)
files <- files[substr(files, n-3, n) == '.gdb']
files
}

#' Get file year
#'
#' Given a file, get the associated year (in the name).
#'
#' @param file A string vector.
#'
#' @return A string vector.
#'
#' @keywords internal
get_file_year <- function(file) {
name <- basename(file)
year <- readr::parse_number(name)
year
}

#' Get file area (with year)
#'
#' Given a file, get the associated code (in the name), includes the year as the
#' name of the vector elements..
#'
#' @param file A string vector.
#'
#' @return A string vector.
#'
#' @keywords internal
get_file_area <- function(file) {
name <- basename(file)
year <- readr::parse_number(name)
pre <- paste0("ACS_", year, "_5YR_")
for (i in seq_along(name)) {
name[i] <- sub(pre[i], "", name[i])
name[i] <- sub('.gdb', "", name[i])
name[i] <- sub('.zip', "", name[i])
}
names(name) <- year
name
}


#' url_file_exists
#'
#' https://stackoverflow.com/questions/60318926/how-to-check-if-file-exists-in-the-url-before-use-download-file-in-r
#'
#' @param url A string.
#'
#' @return A boolean
#'
#' @keywords internal
url_file_exists <- function(url) {
head_url <- httr::HEAD(url)
(head_url$all_headers[[1]]$status == 200)
}


#' Name to title
#'
#' @param name A string.
#'
#' @return A string
#'
#' @keywords internal
name_to_title <- function(name) {
stringr::str_trim(stringr::str_to_title(string = gsub('_', ' ', name), locale = "en"))
}
Loading