-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from timflutre/get_cultivars_list
add get_cultivars_list with tests
- Loading branch information
Showing
6 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' @title Get the cultivar names for a plt.xml file | ||
#' | ||
#' @description Extracts the cultivar names from a plant file | ||
#' | ||
#' @param file The path of a plant file. | ||
#' | ||
#' @return A vector of cultivar names | ||
#' | ||
#' @examples | ||
#' path <- get_examples_path(file_type = "xml") | ||
#' | ||
#' # Read from a plant file (all cultivars available in a plant file) | ||
#' cv_list <- get_cultivars_list(file = file.path(path, "file_plt.xml")) | ||
#' | ||
#' @export | ||
#' | ||
get_cultivars_list <- function(file) { | ||
|
||
## get_param_xml(file, param="variete") # returns a list of lists | ||
|
||
xml_doc <- xmldocument(file) | ||
|
||
stopifnot(is_stics_plt(xml_doc)) | ||
|
||
xml_name <- "variete" | ||
|
||
cv_list <- unique( | ||
unlist( | ||
lapply( | ||
XML::getNodeSet(doc = xml_doc@content, path = paste0("//", xml_name)), | ||
function(x) { | ||
XML::xmlGetAttr(x, "nom") | ||
} | ||
) | ||
) | ||
) | ||
|
||
return(cv_list) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
library(SticsRFiles) | ||
|
||
stics_version <- get_stics_versions_compat()$latest_version | ||
version_num <- get_version_num() | ||
|
||
xml_plant <- file.path( | ||
get_examples_path("xml", stics_version = stics_version), | ||
"file_plt.xml" | ||
) | ||
|
||
cultivar_names <- get_cultivars_list(file = xml_plant) | ||
|
||
context("Getting returned type") | ||
test_that("type, character vector", { | ||
expect_is(cultivar_names, "character") | ||
}) | ||
|
||
context("checking existing cultivar name") | ||
cv_name <- "Sol" | ||
test_that("name", { | ||
expect_true(cv_name %in% cultivar_names) | ||
}) | ||
|
||
context("checking non-existing cultivar name") | ||
cv_name <- "SolTest" | ||
test_that("name", { | ||
expect_false(cv_name %in% cultivar_names) | ||
}) |