Skip to content

Commit fd0735e

Browse files
update documentation
1 parent c60a4f9 commit fd0735e

18 files changed

Lines changed: 472 additions & 289 deletions

‎NAMESPACE‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ export(fetch_template)
2121
export(find_comments)
2222
export(flag_missing_weather)
2323
export(get_cdata)
24-
export(get_dataset_varkeys)
2524
export(get_field_data)
2625
export(get_field_data0)
2726
export(get_kc_token)
28-
export(get_leaf_ids)
2927
export(get_sensor_data)
3028
export(get_soil_profile)
3129
export(get_soil_texture)
3230
export(get_template_version)
33-
export(get_varkey)
3431
export(get_weather_data)
3532
export(icasa_long_to_short)
3633
export(identify_production_season)

‎R/preserve_custom_attributes.R‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
#' Extract metadata into a flat list using only local level names
1+
#' Extract custom attributes into a flat list using local-level names
2+
#'
3+
#' Recursively traverses a nested list object and collects non-structural attributes at each level
4+
#' into a single flat list, keyed by local node name.
5+
#'
6+
#' @param obj A list object (or any R object) to inspect for custom attributes.
7+
#' @param node_name A string giving the key to assign to the current level's attributes in the output list.
8+
#' Defaults to \code{"root"}.
9+
#'
10+
#' @details Structural attributes (\code{names}, \code{row.names}, \code{dim}, \code{dimnames}, \code{class},
11+
#' \code{levels}) are ignored at every level. Recursion proceeds into list elements but stops at data frames.
12+
#' Unnamed list elements are keyed by their integer index (as a character string). If multiple nodes share the
13+
#' same local name, later entries will overwrite earlier ones in the flat output.
14+
#'
15+
#' @return A named flat list where each element is itself a named list of custom attributes belonging to that node.
16+
#' Nodes without custom attributes are omitted.
217
#'
3-
#' @param obj The list object to inspect
4-
#' @param node_name The name to assign to the current level (default "root")
5-
#' @return A flat list of attribute lists, keyed by the local node name.
6-
#'
718
#' @noRd
819
#'
920

‎R/read_dssat2.R‎

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#' # Read sample cultivar file
2222
#' cul <- read_cul(sample_cul_file)
2323
#'
24-
#'
2524

2625
read_cul2 <- function(file_name, col_types=NULL, col_names=NULL,
2726
left_justified=c('VAR#', 'VARNAME\\.*', 'VAR-NAME\\.*','VRNAME\\.*'),
@@ -148,19 +147,19 @@ read_sol2 <- function(file_name, id_soil = NULL, nested = TRUE){
148147

149148
# Specify column types
150149
col_types <- readr::cols(
151-
` LAT`=col_double(),
152-
` LONG`=col_double(),
153-
SSAT=col_double(),
154-
` SCS FAMILY`=col_character(),
155-
` SCS Family`=col_character(),
156-
SCOM=col_character(),
157-
COUNTRY=col_character(),
158-
SITE=col_character(),
159-
SMHB=col_character(),
160-
SMPX=col_character(),
161-
SMKE=col_character(),
162-
SLMH=col_character(),
163-
SLB=col_double()
150+
` LAT` = col_double(),
151+
` LONG` = col_double(),
152+
SSAT = col_double(),
153+
` SCS FAMILY` = col_character(),
154+
` SCS Family` = col_character(),
155+
SCOM = col_character(),
156+
COUNTRY = col_character(),
157+
SITE = col_character(),
158+
SMHB = col_character(),
159+
SMPX = col_character(),
160+
SMKE = col_character(),
161+
SLMH = col_character(),
162+
SLB = col_double()
164163
)
165164
# {.$cols <- c(.$cols,col_types$cols);.}
166165

@@ -258,18 +257,21 @@ read_sol2 <- function(file_name, id_soil = NULL, nested = TRUE){
258257
}
259258

260259

261-
#' Find comment lines
260+
#' Find comment lines in raw DSSAT file content
262261
#'
263-
#' Scans raw lines for comments (lines beginning with "!") and returns them
264-
#' along with their line numbers.
262+
#' Identifies lines beginning with \code{!} (the DSSAT comment character) in a character vector of raw file content.
265263
#'
266-
#' @param raw A character vector where each element is a line of text.
264+
#' @param raw A character vector where each element represents one line of a DSSAT input file.
267265
#'
268-
#' @return A data.frame with two columns: `line_number` (the original index)
269-
#' and `comment_text` (the full text of the comment line).
266+
#' @return A data frame with two columns:
267+
#' \describe{
268+
#' \item{line_number}{Integer index of each comment line within \code{raw}.}
269+
#' \item{comment_text}{The full text of each comment line.}
270+
#' }
271+
#' Returns an empty data frame (zero rows) if no comment lines are found.
270272
#'
271273
#' @export
272-
#'
274+
#'
273275

274276
find_comments <- function(raw) {
275277

@@ -284,11 +286,26 @@ find_comments <- function(raw) {
284286
}
285287

286288

287-
#' Helper function to link comments to pedon
289+
#' Link soil file comment lines to their respective pedons
288290
#'
291+
#' Associates comment lines found in a DSSAT soil file with the most relevant pedon, combining general
292+
#' (file-header) comments with pedon-specific ones.
289293
#'
290-
#' @noRd
294+
#' @param comments_lines A data frame as returned by \code{find_comments()}, with columns \code{line_number}
295+
#' and \code{comment_text}.
296+
#' @param pedon_start_end A data frame describing pedon extents, with at least columns \code{PEDON} (pedon identifier)
297+
#' and \code{start} (integer line number where each pedon begins).
291298
#'
299+
#' @details Comment lines appearing before the first pedon are treated as general (file-level) comments and are
300+
#' prepended to every pedon's comment list. Comment lines appearing after the first pedon start are assigned to
301+
#' the pedon whose start line is closest (by absolute distance). The combined comments for each pedon are returned
302+
#' in ascending line-number order.
303+
#'
304+
#' @return A named list with one element per pedon (named by \code{PEDON}). Each element is a character vector of
305+
#' comment strings associated with that pedon. Returns an empty list if either input has zero rows.
306+
#'
307+
#' @noRd
308+
#'
292309

293310
link_soil_comments <- function(comments_lines, pedon_start_end) {
294311

0 commit comments

Comments
 (0)