Skip to content

Commit 3cfcb4b

Browse files
committed
simplify docs and comments
1 parent 3a5cbb2 commit 3cfcb4b

2 files changed

Lines changed: 39 additions & 55 deletions

File tree

R/find.R

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,41 @@
77
#' specified by `download_directory` parameter) and the input `place` is
88
#' performed using `list.files()`, setting the `pattern` argument equal to the
99
#' basename of the URL associated to the input `place`. For example, if you
10-
#' specify `place = "Isle of Wight"`, then the input is matched (via
11-
#' [`oe_match()`]) with the URL of Isle of Wight's `.osm.pbf` file, and the
12-
#' files are selected using a pattern equal to the basename of that URL.
10+
#' specify `place = "Isle of Wight"`, then your input is matched (via
11+
#' [`oe_match()`]) with the URL of Isle of Wight. Finally, the files are
12+
#' selected using a `pattern` equal to the basename of that URL.
1313
#'
14-
#' If there is no file in the `download_directory` that can be matched with the
15-
#' basename of the URL and `download_if_missing` parameter is equal to `TRUE`, then the
16-
#' function tries to download and read a new file from the chosen
17-
#' provider (`geofabrik` is the default provider). If `download_if_missing`
18-
#' parameter is equal to `FALSE` (default value), then the function stops with
19-
#' an error.
14+
#' If there is no file in the `download_directory` that can be matched with
15+
#' the basename of the URL and `download_if_missing` is `TRUE`, then the
16+
#' function tries to download it (`geofabrik` is the default provider) and
17+
#' returns the path. Otherwise it stops with an error.
2018
#'
21-
#' By default, this function returns the path of `.pbf` and `.gpkg` files
22-
#' associated with the input place (if any). You can exclude one of the two
23-
#' formats setting the arguments `return_pbf` or `return_gpkg` to `FALSE`.
19+
#' By default, this function returns the path of both `.osm.pbf` and `.gpkg`
20+
#' files associated with the input place (if any). You can exclude one of the
21+
#' two formats using the arguments `return_pbf` or `return_gpkg` to `FALSE`.
2422
#'
25-
#' @param download_directory Directory where the files downloaded by osmextract
26-
#' are stored. By default it is equal to [`oe_download_directory()`].
27-
#' @param download_if_missing Attempt to download the file if it cannot be
28-
#' found? `FALSE` by default.
23+
#' @param download_directory Directory where the function looks for matches.
24+
#' @param download_if_missing Should we attempt to download the matched file if
25+
#' it cannot be found? `FALSE` by default.
2926
#' @param return_pbf Logical of length 1. If `TRUE`, the function returns the
30-
#' path of the pbf file that matches the input `place`.
27+
#' path of the .osm.pbf file that matches the input `place`.
3128
#' @param return_gpkg Logical of length 1. If `TRUE`, the function returns the
32-
#' path of the gpkg file that matches the input `place`.
29+
#' path of the .gpkg file that matches the input `place`.
3330
#' @param ... Extra arguments that are passed to [`oe_match()`] and [`oe_get()`].
34-
#' Please note that you cannot modify the argument `download_only`.
31+
#' Please note that you cannot pass the argument `download_only`.
3532
#' @inheritParams oe_get
3633
#'
3734
#' @return A character vector of length one (or two) representing the path(s) of
3835
#' the `.pbf`/`.gpkg` files associated with the input `place`. The files are
39-
#' sorted in alphabetical order which implies that if both formats are present
40-
#' in the `download_directory`, then the `.gpkg` file is returned first.
36+
#' sorted in alphabetical order, which implies that if both formats are
37+
#' present in the `download_directory`, then the `.gpkg` file should be
38+
#' returned first.
4139
#'
4240
#' @export
4341
#' @examples
4442
#' # Copy the ITS file to tempdir() to make sure that the examples do not
4543
#' # require internet connection. You can skip the next 4 lines (and start
4644
#' # directly with oe_get_keys) when running the examples locally.
47-
#'
4845
#' res = file.copy(
4946
#' from = system.file("its-example.osm.pbf", package = "osmextract"),
5047
#' to = file.path(tempdir(), "test_its-example.osm.pbf"),
@@ -90,19 +87,11 @@ oe_find = function(
9087
)
9188
}
9289

93-
# I decided the approach described in @details since I cannot simply use
94-
# list.files(pattern = place) because the names of the files could be
95-
# different from the input place. Check
96-
# https://github.com/ropensci/osmextract/pull/123 to see the approach
97-
# originally adopted.
98-
99-
# First I need to match the input place with a URL
10090
matched_place = oe_match(place, provider = provider, quiet = quiet, ...)
10191
matched_URL = matched_place[["url"]]
10292

103-
# Then I extract from the URL the file name
104-
if (tools::file_ext(tools::file_path_sans_ext(matched_URL)) == "osm") {
10593
# I need the double file_path_san_ext to cancel the .osm and the .pbf
94+
if (tools::file_ext(tools::file_path_sans_ext(matched_URL)) == "osm") {
10695
pattern = tools::file_path_sans_ext(
10796
tools::file_path_sans_ext(basename(matched_URL))
10897
)
@@ -118,15 +107,13 @@ oe_find = function(
118107
paste0(pattern, "\\.gpkg$")
119108
}
120109

121-
# Extract the files that match the pattern
122110
downloads = list.files(
123111
download_directory,
124112
full.names = TRUE,
125113
pattern = pattern,
126114
ignore.case = TRUE
127115
)
128116

129-
# Return the matched paths (if any)
130117
if (length(downloads) > 0) {
131118
return(downloads)
132119
}

man/oe_find.Rd

Lines changed: 19 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)