Skip to content

Commit 3ed5fa8

Browse files
committed
doc edits for load_tree_data()
1 parent 6ab5946 commit 3ed5fa8

2 files changed

Lines changed: 57 additions & 41 deletions

File tree

R/load_tree_data.R

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,57 @@
11
#' Load tree data from a file or database connection
22
#'
3-
#' `load_tree_data()` fetches tree records from a data source, most commonly
4-
#' a comma-separated values (CSV) file, a SQLite database file (.db, .sqlite,
3+
#' `load_tree_data()` fetches tree records from a data source, typically a
4+
#' comma-separated values (CSV) file, a SQLite database file (.db, .sqlite,
55
#' .gpkg), or a PostgreSQL database connection. Other data sources are also
66
#' possible. File-based sources can be read from compressed archives without
7-
#' prior extraction (e.g., .zip), and network-hosted files can be read directly
8-
#' without prior download (see Details).
7+
#' prior extraction if desired (e.g., .zip), and network-hosted files can be
8+
#' read directly without prior download (see Details). This function provides
9+
#' certain conveniences, but tree data could also be loaded in various other
10+
#' ways (e.g., `read.csv()`).
911
#'
1012
#' @details
11-
#' A data source is typically specified as one of the following:
13+
#' A data source is most commonly specified as one of the following:
1214
#'
1315
#' CSV file\cr
1416
#' Path to a text file with `".csv"` extension. For files structured as CSV,
1517
#' but not ending with the `".csv"` extension, a `"CSV:"` prefix can be added
1618
#' before the filename to force loading as CSV format.
1719
#'
1820
#' SQLite database\cr
19-
#' Path to a SQLite file. File extensions are typically `".db"` or `".sqlite"`.
20-
#' GeoPackage SQLite files with `".gpkg"` extension are also supported.
21+
#' Path to a SQLite file. The file extension is generally either `".db"` or
22+
#' `".sqlite"`, but GeoPackage files with the `".gpkg"` extension are also
23+
#' supported.
2124
#'
2225
#' PostgreSQL database\cr
2326
#' A connection string in one of the following formats:
2427
#' ```
25-
#' src <- "PG:dbname=databasename"
28+
#' "PG:dbname=databasename"
2629
#'
27-
#' src <- "PG:dbname='db' host='addr' port='5432' user='x' password='y'"
30+
#' "PG:dbname='db' host='addr' port='5432' user='x' password='y'"
2831
#'
29-
#' src <- "PG:service=servicename"
32+
#' "PG:service=servicename"
3033
#'
31-
#' src <- "postgresql://[usr[:pwd]@][netloc][:port][/db][?param1=val1&...]"
34+
#' "postgresql://[user[:pwd]@][netloc][:port][/dbname][?param1=val1&...]"
3235
#' ```
3336
#'
3437
#' GDAL Virtual File Systems are also supported. This allows, for example,
3538
#' reading from compressed archives such as `".zip"` without prior extraction.
3639
#' The syntax in that case uses the `"/vsizip/"` prefix:
3740
#' ```
3841
#' # relative path to the .zip:
39-
#' src <- "/vsizip/MT_CSV.zip/MT_TREE.csv"
42+
#' f <- "/vsizip/MT_CSV.zip/MT_TREE.csv"
4043
#'
4144
#' # absolute path to the .zip:
42-
#' src <- "/vsizip//home/ctoney/data/MT_CSV.zip/MT_TREE.csv"
45+
#' f <- "/vsizip//home/ctoney/data/MT_CSV.zip/MT_TREE.csv"
4346
#'
4447
#' # on Windows:
45-
#' src <- "/vsizip/c:/users/ctoney/MT_CSV.zip/MT_TREE.csv"
48+
#' f <- "/vsizip/c:/users/ctoney/MT_CSV.zip/MT_TREE.csv"
4649
#' ```
4750
#'
4851
#' Network-hosted files can also be read without prior download using the
4952
#' `"/vsicurl/"` prefix:
5053
#' ```
51-
#' src <- "/vsicurl/https://apps.fs.usda.gov/fia/datamart/CSV/MT_TREE.csv"
54+
#' vsi_f <- "/vsicurl/https://apps.fs.usda.gov/fia/datamart/CSV/MT_TREE.csv"
5255
#' ```
5356
#'
5457
#' For more details, including supported VSI prefixes for cloud storage services
@@ -59,15 +62,17 @@
5962
#' database connection string (see Details).
6063
#' @param table Optional character string giving the name of a table in `src`
6164
#' from which tree records will be fetched. Generally needed with database
62-
#' sources containing multiple tables, as opposed to a single-table source such
63-
#' as a CSV file.
65+
#' sources containing multiple tables (as opposed to a single-table source such
66+
#' as a CSV file).
6467
#' @param columns Optional character vector specifying a subset of column names
65-
#' in the source table to include in the result set.
68+
#' in the source table to include in the result set. Defaults to
69+
#' [DEFAULT_TREE_COLUMNS]. Can also be set to `NULL` or empty string (`""`) to
70+
#' read all columns in the source table.
6671
#' @param sql Optional character string containing a SQL SELECT statement to
67-
#' execute on `src` (instead of selecting all records potentially from a subset
72+
#' execute on `src` (instead of selecting all records, potentially from a subset
6873
#' of columns, i.e., mutually exclusive with `table` and/or `columns`).
6974
#' @return
70-
#' A data frame containing the tree records fetched from `src`.
75+
#' A data frame containing tree records fetched from `src`.
7176
#'
7277
#' @note
7378
#' `src` can be any GDAL supported dataset. A full list of formats supported by
@@ -79,6 +84,9 @@
7984
#'
8085
#' For more details: \url{https://gdal.org/en/stable/drivers/vector/index.html}
8186
#'
87+
#' @seealso
88+
#' [DEFAULT_TREE_COLUMNS]
89+
#'
8290
#' @examples
8391
#' # Lolo NF, single-condition forest plots, INVYR 2022, from public FIADB
8492
#' f <- system.file("extdata/mt_lnf_2022_1cond_tree.csv", package="FIAstemmap")
@@ -143,7 +151,7 @@ load_tree_data <- function(src, table = NULL, columns = DEFAULT_TREE_COLUMNS,
143151
}
144152

145153
if (!methods::is(ds, "Rcpp_GDALVector")) {
146-
cli::cli_alert_danger("failed to access tree data in {.path {src}}")
154+
cli::cli_alert_danger("Failed to access tree data in {.path {src}}")
147155
if (!is.null(sql))
148156
stop("execute SQL failed on 'src'", call. = FALSE)
149157
else

man/load_tree_data.Rd

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

0 commit comments

Comments
 (0)