diff --git a/.gitignore b/.gitignore index 479a553f65bf500f3d59ab52846bf076daeec9ea..66f9146ad5c740a6c8ef8e67f7ac34dcbe4ffbeb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ stacomir.Rproj /~import_coe20092015.csv .dbeaver/project-settings.json docs +tests/testthat/junit_result.xml diff --git a/R/stacomi.R b/R/stacomi.R index f4d5a559792d02c74856d46dc44ec44ba51a56cc..a7c3bbb6a6c5f04f4ac660f82ddc1727fbbbeb34 100644 --- a/R/stacomi.R +++ b/R/stacomi.R @@ -1,88 +1,93 @@ #' -#' +#' #' Internal function, tests the connection and if it works loads the stacomi interface #' @note \code{base} is copied by stacomi into envir_stacomi. Same for \code{database_expected} -#' +#' #' @param ... Other arguments #' @return Nothing #' @author Cedric Briand \email{cedric.briand@eptb-vilaine.fr} #' @keywords internal load_stacomi <- function(...) { - - # assigned when passing through stacomi - database_expected <- get("database_expected", envir_stacomi) # logical true or false - - if (database_expected) { - sch <- get_schema() - dbname <- options("stacomiR.dbname")[[1]] - host <- options("stacomiR.host")[[1]] - port <- options("stacomiR.port")[[1]] - user <- options("stacomiR.user")[[1]] - password <- options("stacomiR.password")[[1]] - if (user=="") { - # this is the default options at start - # if interactive will try to set the options upon loading - if (interactive()){ - user <- readline(prompt="Enter user: ") - options("stacomiR.user"=user) - password <- readline(prompt="Enter password: ") - options("stacomiR.password"=password) - } else { - user <- "group_stacomi" - password <- "group_stacomi" - warning('no user set by default, reverted to user <- "postgres" and password <- "postgres", + # assigned when passing through stacomi + database_expected <- get("database_expected", envir_stacomi) # logical true or false + + if (database_expected) { + sch <- get_schema() + dbname <- options("stacomiR.dbname")[[1]] + host <- options("stacomiR.host")[[1]] + port <- options("stacomiR.port")[[1]] + user <- options("stacomiR.user")[[1]] + password <- options("stacomiR.password")[[1]] + if (user == "") { + # this is the default options at start + # if interactive will try to set the options upon loading + if (interactive()) { + user <- readline(prompt = "Enter user: ") + options("stacomiR.user" = user) + password <- readline(prompt = "Enter password: ") + options("stacomiR.password" = password) + } else { + user <- "group_stacomi" + password <- "group_stacomi" + warning('no user set by default, reverted to user <- "postgres" and password <- "postgres", you can change it with options("stacomiR.user"=user) and options("stacomiR.password"=password)') - } - } - - - con = new("ConnectionDB") - e = expression(con <- connect(con)) - con = tryCatch(eval(e), error = function(e) e) - if ("Rcpp::exception"%in%class(con)){ - cat(con$message) - test <- FALSE - } else { - test <- TRUE - pool::poolClose(con@connection) - } - - - - # second test to check that the database is working OK - - if (test) { - requete = new("RequeteDB") - requete@sql = paste0("select count(*) from ref.tr_taxon_tax") - message <- NULL - requete <- stacomirtools::query(requete) - if (grepl("Error",requete@status)) stop(requete@status) - if (nrow(requete@query) == 0) { - # the database link is not working or the - # schema - funout(paste(gettext("Problem during the test, connection to the database is established but failed to connect to the right schema argument passed to stacomi", - domain = "R-stacomiR"), "\n", - gettext("dbname", domain = "R-stacomiR")," :", dbname, "\n", - gettext("User", domain = "R-stacomiR"), " :", user, "\n", - gettext("Port", domain = "R-stacomiR"), " :", port, "\n", - gettext("Host", domain = "R-stacomiR"), " :", host, "\n", - gettext("Password", domain = "R-stacomiR"), " :", password), - gettext("schema", domain = "R-stacomiR"), " :", sch) - } - - } else { - # the test has failed and the user will be prompted to another - funout(paste(gettext("Problem when testing the DB connection", domain = "R-stacomiR"), - gettext("dbname", domain = "R-stacomiR")," :", dbname, "\n", - gettext("User", domain = "R-stacomiR"), " :", user, "\n", - gettext("Port", domain = "R-stacomiR"), " :", port, "\n", - gettext("Host", domain = "R-stacomiR"), " :", host, "\n", - gettext("Password", domain = "R-stacomiR"), " :", password)) - } # end else test (else == the test didn't pass, we have to change the name and password - } else { - # here : database_expected=FALSE we don't want to check the connection - # at all... - } + } + } + + + con <- new("ConnectionDB") + e <- expression(con <- connect(con)) + con <- tryCatch(eval(e), error = function(e) e) + if ("Rcpp::exception" %in% class(con)) { + cat(con$message) + test <- FALSE + } else { + test <- TRUE + pool::poolClose(con@connection) + } + + + + # second test to check that the database is working OK + + if (test) { + requete <- new("RequeteDB") + requete@sql <- paste0("select count(*) from ref.tr_taxon_tax") + message <- NULL + requete <- stacomirtools::query(requete) + if (grepl("Error", requete@status)) stop(requete@status) + if (nrow(requete@query) == 0) { + # the database link is not working or the + # schema + funout( + paste( + gettext("Problem during the test, connection to the database is established but failed to connect to the right schema argument passed to stacomi", + domain = "R-stacomiR" + ), "\n", + gettext("dbname", domain = "R-stacomiR"), " :", dbname, "\n", + gettext("User", domain = "R-stacomiR"), " :", user, "\n", + gettext("Port", domain = "R-stacomiR"), " :", port, "\n", + gettext("Host", domain = "R-stacomiR"), " :", host, "\n", + gettext("Password", domain = "R-stacomiR"), " :", password + ), + gettext("schema", domain = "R-stacomiR"), " :", sch + ) + } + } else { + # the test has failed and the user will be prompted to another + funout(paste( + gettext("Problem when testing the DB connection", domain = "R-stacomiR"), + gettext("dbname", domain = "R-stacomiR"), " :", dbname, "\n", + gettext("User", domain = "R-stacomiR"), " :", user, "\n", + gettext("Port", domain = "R-stacomiR"), " :", port, "\n", + gettext("Host", domain = "R-stacomiR"), " :", host, "\n", + gettext("Password", domain = "R-stacomiR"), " :", password + )) + } # end else test (else == the test didn't pass, we have to change the name and password + } else { + # here : database_expected=FALSE we don't want to check the connection + # at all... + } } @@ -91,42 +96,44 @@ load_stacomi <- function(...) { #' stacomi Main launcher for program stacomi -#' +#' #' When \code{database_expected=FALSE} a connection to the database is not expected. Therefore test are run by calling examples object stored in Rdata. #' To change the language use Sys.setenv(LANG = 'fr') or Sys.setenv(LANG = 'en') #' @param database_expected Boolean, if \code{TRUE} pre launch tests will be run to test the connection validity #' @param datawd The data working directory #' @param sch The schema in the stacomi database default 'test'. #' @return Nothing, called for its side effect of loading -#' @usage stacomi(database_expected=TRUE, datawd = "~", sch = "test") +#' @usage stacomi(database_expected=TRUE, datawd = tempdir(), sch = "test") #' @author Cedric Briand \email{cedric.briand@eptb-vilaine.fr} #' @examples -#' -#' require(stacomiR) -#' #launch stacomi -#' \dontrun{ -#' stacomi(database_expected=TRUE, datawd='~',sch= "iav") +#' +#' require(stacomiR) +#' # launch stacomi +#' \dontrun{ +#' stacomi(database_expected = TRUE, datawd = tempdir(), sch = "iav") #' } #' # launch stacomi without connection to the database -#' stacomi(database_expected=FALSE) +#' stacomi(database_expected = FALSE) #' # launch stacomi with options #' options( -#' stacomiR.dbname = "bd_contmig_nat", -#' stacomiR.host = readline(prompt = "Enter host: "), -#' stacomiR.port = "5432", -#' stacomiR.user = readline(prompt = "Enter user: "), -#' stacomiR.password = readline(prompt = "Enter password: ") -#') +#' stacomiR.dbname = "bd_contmig_nat", +#' stacomiR.host = readline(prompt = "Enter host: "), +#' stacomiR.port = "5432", +#' stacomiR.user = readline(prompt = "Enter user: "), +#' stacomiR.password = readline(prompt = "Enter password: ") +#' ) #' # another usefull option to print all queries run by stacomiR to the console -#' options('stacomiR.printqueries'= TRUE) +#' options("stacomiR.printqueries" = TRUE) #' @export -stacomi = function(database_expected = TRUE, datawd = "~", sch = "test") { - assign("database_expected", database_expected, envir = envir_stacomi) - # values assigned in the envir_stacomi - assign("datawd", datawd, envir = envir_stacomi) - assign("sch", paste(sch, ".", sep = ""), envir = envir_stacomi) - load_stacomi() - invisible(NULL) +stacomi <- function(database_expected = TRUE, + datawd = tempdir(), + sch = "test") { + assign("database_expected", database_expected, envir = envir_stacomi) + # values assigned in the envir_stacomi + assign("datawd", datawd, envir = envir_stacomi) + assign("sch", paste(sch, ".", sep = ""), envir = envir_stacomi) + load_stacomi() + invisible(NULL) } @@ -135,7 +142,7 @@ stacomi = function(database_expected = TRUE, datawd = "~", sch = "test") { #' Working environment for stacomiR created when launching stacomi() -#' +#' #' This is where the graphical interface stores its objects #' try \code{ls(envir=envir_stacomi)} #' @keywords environment diff --git a/README.md b/README.md index 98ecdf5af395c2f38f903b1d821e5d428984c7d1..4a0d8ebbac8c5b6473d195c5e26f4ef889b0dc8c 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,10 @@ database. ``` r library(stacomiR) -#> Le chargement a nécessité le package : stacomirtools -#> Le chargement a nécessité le package : RODBC -#> Le chargement a nécessité le package : DBI -#> Le chargement a nécessité le package : pool +#> Loading required package: stacomirtools +#> Loading required package: RODBC +#> Loading required package: DBI +#> Loading required package: pool stacomi(database_expected = FALSE) ``` @@ -77,8 +77,8 @@ options( stacomiR.dbname = "bd_contmig_nat", stacomiR.host ="localhost", stacomiR.port ="5432", - stacomiR.user = "postgres", - stacomiR.password = "postgres" + stacomiR.user = "stacomi_test", + stacomiR.password = "stacomi_test" ) stacomi(database_expected = TRUE) # set up a basic report for eel two stages (yellow and silver) annual number in pass 5, 6, 12 (fishway, left bank eel pass, right bank eel pass) @@ -92,6 +92,10 @@ r_ann <- choice_c( start_year ="1996", end_year = "2015", silent = TRUE) +#> Warning in .local(object, ...): Attention, year 1996 is not available in the +#> database, available years : none +#> Warning in .local(object, ...): Attention, year 2015 is not available in the +#> database, available years : none r_ann <- connect(r_ann, silent = TRUE) options(o) ``` diff --git a/dev/03_deploy.R b/dev/03_deploy.R index bd41850a28d9b20a5026f166b19d90e8af2c4df4..6346d200ccdc3252a4545cef0b35422c90b12707 100644 --- a/dev/03_deploy.R +++ b/dev/03_deploy.R @@ -18,7 +18,13 @@ rm(list = ls(all.names = TRUE)) devtools::load_all() Sys.setenv("LANGUAGE" = "en") # otherwise problems when running from Rstudio -# GO TO helper.R called before everything to change options. +options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = "stacomi_test", + stacomiR.password = "stacomi_test" +) devtools::test() # this will run load_all() see details about classes below for specific tests #test_local() # check a package during R CMD check test <- capture.output(devtools::test(reporter="junit")) diff --git a/gitlab-ci/check.gitlab-ci.yml b/gitlab-ci/check.gitlab-ci.yml index 3714e3e1c49b6658d40c55038d39f7b3fcdab4b0..8aa145cf9309e6e2ad75902479f469c50c746d89 100644 --- a/gitlab-ci/check.gitlab-ci.yml +++ b/gitlab-ci/check.gitlab-ci.yml @@ -6,7 +6,12 @@ stage: check script: - mkdir -p public/check - - r -e 'devtools::load_all();devtools::check(document = FALSE, args = "--no-tests", check_dir="public/check")' + - | + r -e ' + Sys.setenv("_R_CHECK_SYSTEM_CLOCK_" = 0); + devtools::load_all(); + devtools::check(document = FALSE, args = "--no-tests", check_dir="public/check") + ' artifacts: when: always paths: diff --git a/gitlab-ci/codecov.gitlab-ci.yml b/gitlab-ci/codecov.gitlab-ci.yml index cbd6072bd3d3a225c544b731bbdf88d044bce8ea..209439982229494b49e81c6624323dcc7e47dbff 100644 --- a/gitlab-ci/codecov.gitlab-ci.yml +++ b/gitlab-ci/codecov.gitlab-ci.yml @@ -6,12 +6,20 @@ - Rscript -e 'pak::pkg_install(pkg = c("covr", "DT"), upgrade = FALSE)' - Rscript -e 'pak::pak(pkg = ".", upgrade = FALSE)' - | - Rscript -e 'Sys.setenv("NOT_CRAN"= "true"); devtools::load_all(); - options(stacomiR.dbname = "'$PG_DB'", - stacomiR.host = "'$PG_HOST'", - stacomiR.port = "'$PG_PORT'", - stacomiR.user = "'$PG_USER'", - stacomiR.password ="'PG_USER_PASSWORD'"); + Rscript -e ' + txt_option <- paste0("options(stacomiR.dbname = \"'${PG_DB}'\", + stacomiR.host = \"'${PG_HOST}'\", + stacomiR.port = \"'${PG_PORT}'\", + stacomiR.user = \"'${PG_USER}'\", + stacomiR.password = \"'${PG_USER_PASSWORD}'\")"); + source("gitlab-ci/helper.R"); + copier_option( + file_path = "tests/testthat/helper.R", + new_text = txt_option + ) + ' + - | + Rscript -e 'Sys.setenv("NOT_CRAN"= "true"); devtools::load_all(); covr::gitlab(quiet = FALSE)' coverage: '/Coverage: \d+\.\d+/' artifacts: diff --git a/gitlab-ci/helper.R b/gitlab-ci/helper.R new file mode 100644 index 0000000000000000000000000000000000000000..5d24a742d253dd7f6e4a3b58a569f311b3a87e0d --- /dev/null +++ b/gitlab-ci/helper.R @@ -0,0 +1,16 @@ +copier_option <- function( + file_path = "chemin/vers/votre/fichier.txt", + old_text = "# options here for codecov", + new_text = "mon code" +) { + # Lire le contenu du fichier + file_content <- readLines(file_path, encoding = "UTF-8") + + # Remplacer le texte + new_content <- gsub(old_text, new_text, file_content) + + # Écrire le nouveau contenu dans le fichier + writeLines(new_content, file_path) + + cat("Remplacement effectué avec succès dans le fichier :", file_path, "\n") +} diff --git a/gitlab-ci/unittests.gitlab-ci.yml b/gitlab-ci/unittests.gitlab-ci.yml index d7cf5f95f5b5a751805b777d807939e984716113..b67e0b5fe275ef84402abebdba5cc18e0e6083a2 100644 --- a/gitlab-ci/unittests.gitlab-ci.yml +++ b/gitlab-ci/unittests.gitlab-ci.yml @@ -3,24 +3,22 @@ stage: test script: - Rscript -e 'pak::pkg_install(pkg = c("XML"), upgrade = FALSE)' + - Rscript -e 'cat("PG_HOST = '${PG_HOST}'\n")' - | - r -e "devtools::load_all(); - options(stacomiR.dbname = "'$PG_DB'", - stacomiR.host = "'$PG_HOST'", - stacomiR.port = "'$PG_PORT'", - stacomiR.user = "'$PG_USER'", - stacomiR.password ="'PG_USER_PASSWORD'"); - test <- capture.output(devtools::test(reporter='junit')) ; - XML::saveXML(XML::xmlParse(test[grep('?xml version', test):length(test)]), file = 'public/test.xml')" + Rscript -e 'devtools::load_all(); + options(stacomiR.dbname = "'${PG_DB}'", + stacomiR.host = "'${PG_HOST}'", + stacomiR.port = "'${PG_PORT}'", + stacomiR.user = "'${PG_USER}'", + stacomiR.password ="'${PG_USER_PASSWORD}'"); + devtools::test(reporter=JunitReporter$new(file = "junit_result.xml"));' artifacts: when: always # You should set the job that uploads the screenshot to #artifacts:when: always so that it still uploads a screenshot #when a test fails. - paths: - - public/test.xml reports: - junit: public/test.xml + junit: tests/testthat/junit_result.xml expire_in: 30 days # en dev diff --git a/gitlab-ci/update_check.gitlab-ci.yml b/gitlab-ci/update_check.gitlab-ci.yml index 2e32a7572e54787f2e648d450e6f88f67638299d..44383f0ecc2f1edaac0b783fac567af8ae39a848 100644 --- a/gitlab-ci/update_check.gitlab-ci.yml +++ b/gitlab-ci/update_check.gitlab-ci.yml @@ -7,7 +7,12 @@ script: - mkdir -p public/check - Rscript -e 'renv::update()' - - r -e 'devtools::load_all();devtools::check(document = FALSE, args = "--no-tests", check_dir="public/check")' + - | + r -e ' + Sys.setenv("_R_CHECK_SYSTEM_CLOCK_" = 0); + devtools::load_all(); + devtools::check(document = FALSE, args = "--no-tests", check_dir="public/check") + ' artifacts: when: always paths: diff --git a/inst/examples/report_mig_interannual-example.R b/inst/examples/report_mig_interannual-example.R index 7e0e1b2bc14cb9ce76951a1f5de0abaf1f64bfce..2a4181b6d8c6cc94e0a50d585a52819d5832120a 100644 --- a/inst/examples/report_mig_interannual-example.R +++ b/inst/examples/report_mig_interannual-example.R @@ -121,10 +121,22 @@ if (requireNamespace("ggplot2", quietly = TRUE) & # with the silent=TRUE argument, it's always the latest year that is selected, # otherwise the user is prompted with a choice, to select the year he wants # to compare will all others... -plot(r_mig_interannual, plot.type = "barchart", timesplit = "quinzaine", year_choice = 2015, silent = TRUE) +plot( + r_mig_interannual, + plot.type = "barchart", + timesplit = "quinzaine", + year_choice = 2015, + silent = TRUE +) # Comparison with historical values. Each year and 2 weeks values # is a point on the graph... -plot(r_mig_interannual, plot.type = "pointrange", timesplit = "mois", year_choice = 2015, silent = TRUE) +plot( + r_mig_interannual, + plot.type = "pointrange", + timesplit = "mois", + year_choice = 2015, + silent = TRUE +) ############################################### # Step plot # different years shown in the graph diff --git a/inst/examples/report_sample_char-example.R b/inst/examples/report_sample_char-example.R index 07a35f85c0af484eaf469d280942d6424424b3b2..e73a437510b7d03eb91bc738b5e9b04f093b7f30 100644 --- a/inst/examples/report_sample_char-example.R +++ b/inst/examples/report_sample_char-example.R @@ -78,7 +78,9 @@ plot(r_sample_char, plot.type = "3", silent = TRUE) if (requireNamespace("ggplot2", quietly = TRUE)) { g <- ggplot2::ggplot(r_sample_char@data) + - ggplot2::geom_boxplot(ggplot2::aes(x = annee, y = car_valeur_quantitatif, fill = std_libelle)) + + ggplot2::geom_boxplot( + ggplot2::aes(x = annee, y = car_valeur_quantitatif, fill = std_libelle) + ) + ggplot2::xlab("size") + ggplot2::ylab("year") + ggplot2::scale_fill_manual( "stage & fishway", diff --git a/man/choice_c-report_annual-method.Rd b/man/choice_c-report_annual-method.Rd index 9c5834c597528b6f48f89c89d17fd0f2753c7cc6..4ef9ffb351a19a7912174baac8999bd5a9b82687 100644 --- a/man/choice_c-report_annual-method.Rd +++ b/man/choice_c-report_annual-method.Rd @@ -27,7 +27,7 @@ it should match the ref.tr_taxon_tax referential table in the stacomi database, An object of class \link{report_annual-class} with data selected } \description{ -The choice_c method fills in the data slot for classes \link{ref_dc-class}, \link{ref_taxa-class}, +The choice_c method fills in the data slot for classes \link{ref_dc-class}, \link{ref_taxa-class}, \link{ref_stage-class} and two slots of \link{ref_year-class} } \author{ diff --git a/man/plot-report_mig_mult-missing-method.Rd b/man/plot-report_mig_mult-missing-method.Rd index a8cc9b4d3a68f096f4abdc114e4c737d38179cc2..183d05fe139c92a86ee81d85dd342e61159002fd 100644 --- a/man/plot-report_mig_mult-missing-method.Rd +++ b/man/plot-report_mig_mult-missing-method.Rd @@ -17,7 +17,7 @@ \arguments{ \item{x}{An object of class report_mig_mult} -\item{plot.type}{One of 'standard','step','multiple'. Defaut to \code{standard} the standard report_mig with dc and operation displayed, can also be \code{step} or +\item{plot.type}{One of 'standard','step','multiple','time'. Defaut to \code{standard} the standard report_mig with dc and operation displayed, can also be \code{step} or \code{multiple}} \item{color}{Default NULL, argument passed for the plot.type='standard' method. A vector of color in the following order : (1) working, (2) stopped, (3:7) 1...5 types of operation, diff --git a/man/r_dc.Rd b/man/r_dc.Rd index 14aaa5373394e38f2e6ea624e105081b725b9b77..3f39384b2a5d76aa5e239f7ecbbd7bcc74492c4b 100644 --- a/man/r_dc.Rd +++ b/man/r_dc.Rd @@ -24,7 +24,7 @@ An object of class report_dc with 4 slots: \item{libelle}{label corresponding to per_tar_code} } } - \item{df}{the \code{ref_dc} object with 3 slots filled with data corresponding to the iav postgres schema} + \item{df}{the \code{ref_dc} object with 3 slots filled with data corresponding to the test postgres schema} \item{horodatedebut}{the \code{ref_horodate} with horodate set for starting date} \item{horodatefin}{the \code{ref_horodate} with horodate set for ending date} } diff --git a/man/r_df.Rd b/man/r_df.Rd index 0fcd7c60aa8dd86bec34fde4e6ec1522fd2ebbb9..10c82e4ac5fbb1651870ab8783e25ee39c56ddf2 100644 --- a/man/r_df.Rd +++ b/man/r_df.Rd @@ -23,7 +23,7 @@ An object of class report_df with 4 slots: \item{libelle}{label corresponding to per_tar_code} } } - \item{df}{the \code{ref_df} object with 3 slots filled with data corresponding to the iav postgres schema} + \item{df}{the \code{ref_df} object with 3 slots filled with data corresponding to the test postgres schema} \item{horodatedebut}{the \code{ref_horodate} with horodate set for starting date} \item{horodatefin}{the \code{ref_horodate} with horodate set for ending date}' } diff --git a/man/r_env.Rd b/man/r_env.Rd index d2e8aa94b1c3b5aa7480a0ab7a47695e8c81dd7a..31b8e8944c5b07284146600a896281141f872a59 100644 --- a/man/r_env.Rd +++ b/man/r_env.Rd @@ -7,7 +7,7 @@ \format{ An object of class \link{report_env-class} with data slot loaded: \describe{ - \item{stationMesure}{the \code{ref_env} object with 5 slots filled with data corresponding to the iav postgres schema} + \item{stationMesure}{the \code{ref_env} object with 5 slots filled with data corresponding to the test postgres schema} \item{horodatedebut}{object of class \code{ref_horodate-class} : the start date selected} \item{horodatefin}{object of class \code{ref_horodate-class} : the end date selected} \item{data}{ A dataframe with 723 rows and 6 variables diff --git a/man/r_mig.Rd b/man/r_mig.Rd index e3f0e664d13707c4bac7370d588758eec4067b49..9b72c2e9dfccdc280af5aeb9a9e3f35b0382ce0b 100644 --- a/man/r_mig.Rd +++ b/man/r_mig.Rd @@ -7,7 +7,7 @@ \format{ An object of class report_mig with 8 slots: \describe{ - \item{dc}{the \code{ref_dc} object with 4 slots filled with data corresponding to the iav postgres schema} + \item{dc}{the \code{ref_dc} object with 4 slots filled with data corresponding to the test postgres schema} \item{taxa}{the \code{ref_taxa} the taxa selected} \item{stage}{the \code{ref_stage} the stage selected} \item{timestep}{the \code{ref_timestep_daily} calculated for all 2015} diff --git a/man/r_mig_interannual_vichy.Rd b/man/r_mig_interannual_vichy.Rd index 7f062d3517043f7a25df87fd4482657979c13812..0bbc2c5dd0c3f70d1ba16daebaa9774d5aac88f1 100644 --- a/man/r_mig_interannual_vichy.Rd +++ b/man/r_mig_interannual_vichy.Rd @@ -7,7 +7,7 @@ \format{ An object of class \link{report_mig_interannual-class} with 7 slots: \describe{ - \item{dc}{the \code{ref_dc} object with 4 slots filled with data corresponding to the iav postgres schema} + \item{dc}{the \code{ref_dc} object with 4 slots filled with data corresponding to the test postgres schema} \item{taxa}{the \code{ref_taxa} the taxa selected} \item{stage}{the \code{ref_stage} the stage selected} \item{start_year}{the \code{ref_timestep_daily} calculated for all 2015} diff --git a/man/report_annual-class.Rd b/man/report_annual-class.Rd index 515e871d068f40f7ee94394a0777fe67ec263202..d795f3a3ab3fc7abfbac33110cd2b0bde3614834 100644 --- a/man/report_annual-class.Rd +++ b/man/report_annual-class.Rd @@ -28,11 +28,11 @@ ref_year allows to choose last year of the report} \examples{ # launching stacomi without database for demo stacomi(database_expected=FALSE) -# the following piece of script will load the Arzal dataset and connected to iav postgres schema +# the following piece of script will load the Arzal dataset and connected to test postgres schema # it requires a working database # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ - stacomi(database_expected=TRUE, sch='iav') + stacomi(database_expected=TRUE, sch='test') if (interactive()){ if (!exists("user")){ user <- readline(prompt="Enter user: ") @@ -51,8 +51,8 @@ stacomi(database_expected=FALSE) dc=c(5,6,12), taxa=c("Anguilla anguilla"), stage=c("AGJ","AGG"), - start_year="1996", - end_year="2015", + start_year="2012", + end_year="2013", silent=FALSE) r_ann<-connect(r_ann) } diff --git a/man/report_dc-class.Rd b/man/report_dc-class.Rd index fb0d806f6b13bc1d054badeec744b60b9f26e19e..88ef5bd776ccf2721248a7a3526d56f8b05f1b81 100644 --- a/man/report_dc-class.Rd +++ b/man/report_dc-class.Rd @@ -29,55 +29,50 @@ class allows to draw graphics allowing an overview of the device operation } \examples{ - - -# An example that will work only if the database is present -# and the program installed and comprises the schema iav +# An example that will work only if the database is present +# and the program installed and comprises the schema test # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } +if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.password = password - ) + options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.password = password + ) + } + stacomi(TRUE, sch = "test") + r_dc <- new("report_dc") + r_dc <- choice_c(r_dc, + 5, + horodatedebut = "2012-01-01", + horodatefin = "2015-12-31", + silent = TRUE + ) + r_dc <- connect(r_dc) } - stacomi(TRUE,sch="iav") - r_dc=new("report_dc") - r_dc<-choice_c(r_dc, - 5, - horodatedebut="2000-01-01", - horodatefin="2015-12-31", - silent=TRUE) - r_dc<-connect(r_dc) + ## -## - # this dataset has been loaded by the previous lines - ########################################################### -# Without connexion to the database (use dataset r_dc) + ########################################################### + # Without connexion to the database (use dataset r_dc) ########################################################## - # this option allows to launch the program without the interface to display -# some of the program features. - stacomi(database_expected=FALSE) + # this option allows to launch the program without the interface to display + # some of the program features. + stacomi(database_expected = FALSE) data("r_dc") - plot(r_dc,plot.type="1") - plot(r_dc,plot.type="2") - plot(r_dc,plot.type="3",main="trial title") - plot(r_dc,plot.type="4",main="trial title") -# the following will write in the datawd folder - summary(r_dc) -} - - - + plot(r_dc, plot.type = "1") + plot(r_dc, plot.type = "2") + plot(r_dc, plot.type = "3", main = "trial title") + plot(r_dc, plot.type = "4", main = "trial title") + # the following will write in the datawd folder + summary(r_dc) } \seealso{ diff --git a/man/report_df-class.Rd b/man/report_df-class.Rd index c0c1d8da793d96f7d68956c9e0a6d8f93b2252d2..f7a266a152e7e9d94cfb914bd8c7e9a47c990bbe 100644 --- a/man/report_df-class.Rd +++ b/man/report_df-class.Rd @@ -38,52 +38,46 @@ the status of either the fishway or DC. In the database four types of operation \examples{ stacomi( - database_expected=FALSE) -# An example that will work with the database installed only and schema iav in the database + database_expected = FALSE +) +# An example that will work with the database installed only and schema test in the database # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ - stacomi( - database_expected=TRUE, sch='iav') - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) - r_df=new("report_df") - r_df<-choice_c(r_df, - 1, - horodatedebut="2015-01-01", - horodatefin="2015-12-31", - silent=TRUE) - Sys.setenv(TZ='GMT') - # the times at Arzal are recorded continuously - # they are converted to date when a time appears while the hour is changing - # hence the following - r_df<-connect(r_df) +stacomi( + database_expected = TRUE, sch = "test" +) +if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } +} +options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password +) +r_df <- new("report_df") +r_df <- choice_c(r_df, + 1, + horodatedebut = "2015-01-01", + horodatefin = "2015-12-31", + silent = TRUE +) +r_df <- connect(r_df) } data("r_df") -plot(r_df,plot.type="4") +plot(r_df, plot.type = "4") # the following examples work but take a while to compute \dontrun{ - plot(r_df,plot.type="1") - plot(r_df,plot.type="2",main="A nice title") - plot(r_df,plot.type="3",main="A nice title") +plot(r_df, plot.type = "1") +plot(r_df, plot.type = "2", main = "A nice title") +plot(r_df, plot.type = "3", main = "A nice title") } - - - - - } \seealso{ Other report Objects: diff --git a/man/report_env-class.Rd b/man/report_env-class.Rd index dc7be729a002c992b9223ec106015b3975e90b38..a8d72730e7e977a70096ebb40177eaed5f079bd7 100644 --- a/man/report_env-class.Rd +++ b/man/report_env-class.Rd @@ -24,33 +24,35 @@ joined graphs crossing the information from \link{report_mig_mult-class} and \li \examples{ stacomi( - database_expected=FALSE) + database_expected = FALSE +) \dontrun{ - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) - r_env<-new("report_env") - r_env<-choice_c(r_env, - stationMesure=c("temp_gabion","coef_maree"), - datedebut="2008-01-01", - datefin="2008-12-31", - silent=FALSE) - r_env<-connect(r_env) - -} +if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } +} +options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password +) +r_env <- new("report_env") +r_env <- choice_c(r_env, + stationMesure = c("temp_gabion", "coef_maree"), + datedebut = "2008-01-01", + datefin = "2008-12-31", + silent = FALSE +) +r_env <- connect(r_env) + +} data("r_env") -plot(r_env,silent=TRUE) +plot(r_env, silent = TRUE) } \seealso{ Other report Objects: diff --git a/man/report_ge_weight-class.Rd b/man/report_ge_weight-class.Rd index 53b2e3a0d225f777e1e16e90fc78229ba2a0a4df..9c356a62b8003ea70c704c9d698d42e4b8bb7e51 100644 --- a/man/report_ge_weight-class.Rd +++ b/man/report_ge_weight-class.Rd @@ -50,55 +50,58 @@ request are from august to august (a glass eel season) require(stacomiR) # launching stacomi without selecting the scheme or interface stacomi( - database_expected=FALSE, sch='iav') -# this requires a working database with the schema iav + database_expected = FALSE, sch = "test" +) +# this requires a working database with the schema test # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ - stacomi( - database_expected=TRUE, sch='iav') - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) - #create an instance of the class - r_gew<-new("report_ge_weight") - r_gew@liste<-charge(object=r_gew@liste,listechoice=c("=1",">1","tous"),label="") - # here I'm using weights when number are larger than 1i.e.wet weight - # always choose a date from one year to the next eg 2010 to 2011 - # as the dates are from august to august - r_gew<-choice_c(r_gew, - dc=c(6), - start_year="2009", - end_year="2015", - selectedvalue=">1", - silent=FALSE) - r_gew<-connect(r_gew) - r_gew<-calcule(r_gew) -} +stacomi( + database_expected = TRUE, sch = "test" +) +if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } +} +options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password +) +# create an instance of the class +r_gew <- new("report_ge_weight") +r_gew@liste <- charge(object = r_gew@liste, listechoice = c("=1", ">1", "tous"), label = "") +# here I'm using weights when number are larger than 1i.e.wet weight +# always choose a date from one year to the next eg 2010 to 2011 +# as the dates are from august to august +r_gew <- choice_c(r_gew, + dc = c(6), + start_year = "2009", + end_year = "2014", + selectedvalue = ">1", + silent = FALSE +) +r_gew <- connect(r_gew) +r_gew <- calcule(r_gew) +} # load the dataset generated by previous lines data("r_gew") # the calculation will fill the slot calcdata # A ggplot showing the trend in weight -plot(r_gew, plot.type=1) +plot(r_gew, plot.type = 1) # A plot showing both the data and the trend as recorded in the database -plot(r_gew, plot.type=2) +plot(r_gew, plot.type = 2) # Same as plot.type=1 but with size according to size of the sample, # usefull for wet weights where weight are recorded on a number of glass eel -plot(r_gew, plot.type=3) +plot(r_gew, plot.type = 3) \dontrun{ -# First model with nls, see Guerault and Desaunay (1993) - model(r_gew,model.type="seasonal") - model(r_gew,model.type="seasonal1") +# First model with nls, see Guerault and Desaunay (1993) +model(r_gew, model.type = "seasonal") +model(r_gew, model.type = "seasonal1") } } \seealso{ diff --git a/man/report_mig-class.Rd b/man/report_mig-class.Rd index c1435c6eb1813cb0aae8682c29fd9c9776c87257..9149cba8809abfaf6650b32519315f6eaa9836f1 100644 --- a/man/report_mig-class.Rd +++ b/man/report_mig-class.Rd @@ -37,75 +37,82 @@ method if any weight are found in the data slot.} In practise, the report_mig class uses methods (calcule, connect...) from the more elaborate \link{report_mig_mult-class} } \examples{ -stacomi(database_expected=FALSE) +stacomi(database_expected = FALSE) # If you have a working database -# the following line of code will create the r_mig dataset from the iav (default) +# the following line of code will create the r_mig dataset from the test (default) # schema in the database -\dontrun{ - stacomi(database_expected=TRUE) - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) - stacomi( - database_expected=TRUE) - r_mig=new("report_mig") - r_mig=choice_c(r_mig, - dc=5, - taxa=c("Chelon ramada"), - stage=c("IND"), - datedebut="2015-01-01", - datefin="2015-12-31") - r_mig<-charge(r_mig) +\dontrun{ + stacomi(database_expected = TRUE) + if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } + } + options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password + ) + stacomi(database_expected = TRUE) + r_mig = new("report_mig") + r_mig = choice_c( + r_mig, + dc = 5, + taxa = c("Chelon ramada"), + stage = c("IND"), + datedebut = "2015-01-01", + datefin = "2015-12-31" + ) + r_mig <- charge(r_mig) # launching charge will also load classes associated with the report # e.g. report_ope, report_df, report_dc - r_mig<-connect(r_mig) + r_mig <- connect(r_mig) ######################## -# calculations + # calculations ######################## - r_mig<-calcule(r_mig,silent=TRUE) + r_mig <- calcule(r_mig, silent = TRUE) } ######################## # loading data ## use the following to get the raw data loaded by the connect method # not shown there as the database and program might not be installed -# All three classes report... were created by the charge and connect method +# All three classes report... were created by the charge and connect method # of report_mig_mult # in the previous example ################################ data("r_mig") data("r_mig_ope") -assign("report_ope",r_mig_ope,envir=envir_stacomi) +assign("report_ope", r_mig_ope, envir = envir_stacomi) data("r_mig_df") -assign("report_df",r_mig_df,envir=envir_stacomi) +assign("report_df", r_mig_df, envir = envir_stacomi) data("r_mig_dc") -assign("report_dc",r_mig_dc,envir=envir_stacomi) +assign("report_dc", r_mig_dc, envir = envir_stacomi) #Individual plot for all DC (standard), taxa and stage where data present #silent argument to stop all messages -plot(r_mig,plot.type="standard",silent=TRUE) +plot(r_mig, plot.type = "standard", silent = TRUE) #cumulated migration at the station (all stages and DC grouped) -plot(r_mig,plot.type="step") +plot(r_mig, plot.type = "step") # data will be written in the data directory specified in datawd argument to stacomi default "~" #file \dontrun{ - summary(r_mig,silent=TRUE) + summary(r_mig, silent = TRUE) } # this will write the daily report for later in in the reportnMigrationInterannuelle-class \dontrun{ - write_database(r_mig,silent=TRUE,dbname="bd_contmig_nat",host="localhost",port=5432) + write_database( + r_mig, + silent = TRUE, + dbname = "bd_contmig_nat", + host = "localhost", + port = 5432 + ) } } \seealso{ diff --git a/man/report_mig_char-class.Rd b/man/report_mig_char-class.Rd index 09354e20f321e4f71fcc4de1497a56340ce19d87..2bc863b31e8842b6a0ed9c3b836f0a862b98ad9d 100644 --- a/man/report_mig_char-class.Rd +++ b/man/report_mig_char-class.Rd @@ -54,62 +54,66 @@ using interface_report_mig_char function. require(stacomiR) stacomi( - database_expected=FALSE, sch='logrami') + database_expected = FALSE +) # this requires a database with the schema logrami # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ - stacomi(database_expected=TRUE, sch='logrami') - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) - r_mig_char <- new("report_mig_char") - # here parqual is not in the list - # so this is equivalent to parqual=NULL - # default for echantillon is "with" - r_mig_char <- choice_c(r_mig_char, - dc=c(107,108,101), - taxa=c("Salmo salar"), - stage=c('5','11','BEC','BER','IND'), - parquan=c('C001','1786','1785'), - horodatedebut="2012-01-01", - horodatefin="2012-12-31", - silent=FALSE) - # r_mig_char<-charge(r_mig_char) not necessary there - r_mig_char <- connect(r_mig_char) - -} +stacomi(database_expected = TRUE, sch = "test") +if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } +} +options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password +) +r_mig_char <- new("report_mig_char") +# here parqual is not in the list +# so this is equivalent to parqual=NULL +# default for echantillon is "with" +r_mig_char <- choice_c(r_mig_char, + dc = c(19,20), + taxa = c("Salmo salar"), + stage = c("5"), + parquan = c("C001"), + horodatedebut = "2012-01-01", + horodatefin = "2012-12-31", + silent = FALSE +) +# r_mig_char<-charge(r_mig_char) not necessary there +r_mig_char <- connect(r_mig_char) + +} # load the dataset generated by previous lines data("r_mig_char") -r_mig_char<-calcule(r_mig_char, silent=TRUE) -plot(r_mig_char,plot.type="quant", silent=TRUE) +r_mig_char <- calcule(r_mig_char, silent = TRUE) +plot(r_mig_char, plot.type = "quant", silent = TRUE) # one quantitative parameter found, manual choice of color -plot(r_mig_char,plot.type="quant",color_parm=c("C001"="red"), silent=TRUE) +plot(r_mig_char, plot.type = "quant", color_parm = c("C001" = "red"), silent = TRUE) # age will be plotted as a qualitative variable # here we split size data accoding to the limit known between different ages from # scale reading in the Loire -r_mig_char <- setasqualitative(r_mig_char,par='C001', - breaks=c(0,675,850,2000), - labels=c("age 1","age 2","age 3")) -r_mig_char<-calcule(r_mig_char, silent=TRUE) -plot(r_mig_char, plot.type="qual", silent=TRUE) -plot(r_mig_char, plot.type="crossed") -plot(r_mig_char, plot.type="crossed", - color_parm=c("age 1"="#379ec6","age 2"="#173957","age 3"="#b09953")) -xt<-xtable(r_mig_char) +r_mig_char <- setasqualitative(r_mig_char, + par = "C001", + breaks = c(0, 675, 850, 2000), + labels = c("age 1", "age 2", "age 3") +) +r_mig_char <- calcule(r_mig_char, silent = TRUE) +plot(r_mig_char, plot.type = "qual", silent = TRUE) +plot(r_mig_char, plot.type = "crossed") +plot(r_mig_char, + plot.type = "crossed", + color_parm = c("age 1" = "#379ec6", "age 2" = "#173957", "age 3" = "#b09953") +) +xt <- xtable(r_mig_char) # use method print.xtable to get the output - - } \seealso{ Other report Objects: diff --git a/man/report_mig_env-class.Rd b/man/report_mig_env-class.Rd index 330916b317b6c1b530d21309d7e525a4bbbf1c8c..06aa14414f01ed41e47c9efa10351f8926c3e88b 100644 --- a/man/report_mig_env-class.Rd +++ b/man/report_mig_env-class.Rd @@ -28,45 +28,48 @@ event of the day is displayed on the annual plot. \examples{ require(stacomiR) stacomi( - database_expected=FALSE) + database_expected = FALSE +) # the following will load the data provided the user has access to the database -# with data in the iav example scheme. +# with data in the test example scheme. # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ - stacomi( - database_expected=TRUE) - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) - r_mig_env<-new("report_mig_env") - r_mig_env<-choice_c(r_mig_env, - dc=c(5,6,12), - taxa=c("Anguilla anguilla"), - stage=c("AGJ","AGG","CIV"), - stationMesure=c("temp_gabion","coef_maree","phases_lune"), - datedebut="2008-01-01", - datefin="2008-12-31", - silent=FALSE) - r_mig_env<-charge(r_mig_env) # this is necessary to load operations, DF and DC - r_mig_env<-connect(r_mig_env) - r_mig_env<-calcule(r_mig_env,silent=TRUE) -} +stacomi( + database_expected = TRUE +) +if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } +} +options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password +) +r_mig_env <- new("report_mig_env") +r_mig_env <- choice_c(r_mig_env, + dc = c(5, 6, 12), + taxa = c("Anguilla anguilla"), + stage = c("AGJ", "AGG", "CIV"), + stationMesure = c("temp_gabion", "coef_maree", "phases_lune"), + datedebut = "2010-01-01", + datefin = "2010-12-31", + silent = FALSE +) +r_mig_env <- charge(r_mig_env) # this is necessary to load operations, DF and DC +r_mig_env <- connect(r_mig_env) +r_mig_env <- calcule(r_mig_env, silent = TRUE) +} data("r_mig_env") # An example of plot with custom colors. plot(r_mig_env, - color_station=c("temp_gabion"="red","coef_maree"="blue","phases_lune"="pink"), - color_dc=c("5"="yellow","6"="orange","12"="purple") + color_station = c("temp_gabion" = "red", "coef_maree" = "blue", "phases_lune" = "pink"), + color_dc = c("5" = "yellow", "6" = "orange", "12" = "purple") ) } \seealso{ diff --git a/man/report_mig_interannual-class.Rd b/man/report_mig_interannual-class.Rd index 6b57353fb96c3751c8f4e5c975b375a15e432d41..ae967b97deb1cf16e5d533a331ee0a8d24b60d59 100644 --- a/man/report_mig_interannual-class.Rd +++ b/man/report_mig_interannual-class.Rd @@ -40,182 +40,211 @@ ref_year allows to choose last year of the report} require(stacomiR) # launching stacomi without selecting the scheme or interface stacomi( - database_expected=FALSE, sch='pmp') -# If you have connection to the database with the pmp scheme + database_expected = FALSE, sch = "pmp" +) +# If you have connection to the database with the pmp scheme # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ - stacomi(database_expected=TRUE, sch="pmp") - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) +stacomi(database_expected = TRUE, sch = "pmp") +if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } +} +options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password +) - # (longest historical dataset available - # in France for eel ...) this suppose you have access to the pmp schema... - # a glimpse of the dataset is still available in the r_mig_interannual dataset - # loaded in the package... - r_mig_interannual <- new("report_mig_interannual") - r_mig_interannual <- choice_c(r_mig_interannual, - dc=c(16), - taxa=c("Anguilla anguilla"), - stage=c("PANG"), - start_year="1990", - end_year="2015", - year_choice=NULL, - silent=TRUE) - r_mig_interannual <- charge(r_mig_interannual) - r_mig_interannual <- connect(r_mig_interannual, check=TRUE) - r_mig_interannual <- calcule(r_mig_interannual, silent=TRUE) -} -#############otherwise use this ###################### +# (longest historical dataset available +# in France for eel ...) this suppose you have access to the pmp schema... +# a glimpse of the dataset is still available in the r_mig_interannual dataset +# loaded in the package... +r_mig_interannual <- new("report_mig_interannual") +r_mig_interannual <- choice_c(r_mig_interannual, + dc = c(16), + taxa = c("Anguilla anguilla"), + stage = c("PANG"), + start_year = "1990", + end_year = "2015", + silent = TRUE +) +r_mig_interannual <- charge(r_mig_interannual) +r_mig_interannual <- connect(r_mig_interannual, check = TRUE) +r_mig_interannual <- calcule(r_mig_interannual, silent = TRUE) +} +############# otherwise use this ###################### # load the dataset generated by previous lines data("r_mig_interannual") ####################################################### -# the first plot is of little interest, it allows to see what data +# the first plot is of little interest, it allows to see what data # are available... simple lines # For irregular operations like those reported at the enfrenaux eel ladder.... -plot(r_mig_interannual,plot.type="line", year_choice=2015, silent=TRUE) +plot(r_mig_interannual, plot.type = "line", year_choice = 2015, silent = TRUE) # a plot to show the seasonality, this graph may be misleading if the # migration is not monitored all year round. Note the y unit is not very informative # you need to have the viridis package loaded to run this example -plot(r_mig_interannual,plot.type="density",year_choice=2015, silent=TRUE) +plot(r_mig_interannual, plot.type = "density", year_choice = 2015, silent = TRUE) + \dontrun{ - if (requireNamespace("ggplot2", quietly = TRUE)& - requireNamespace("viridis", quietly = TRUE)){ - g<-get("g",envir=envir_stacomi) - g+ - ggplot2::scale_fill_manual(values=viridis::viridis(22))+ - ggplot2::ggtitle("Saisonnalite de la migration aux Enfrenaux") - } - ############################################# +if (requireNamespace("ggplot2", quietly = TRUE) & + requireNamespace("viridis", quietly = TRUE)) { + g <- get("g", envir = envir_stacomi) + g + + ggplot2::scale_fill_manual(values = viridis::viridis(22)) + + ggplot2::ggtitle("Saisonnalite de la migration aux Enfrenaux") +} +############################################# # the standard plot is showing daily values - ########################################### - plot(r_mig_interannual,plot.type="standard",year_choice=2015,silent=TRUE) +########################################### +plot(r_mig_interannual, plot.type = "standard", year_choice = 2015, silent = TRUE) # Manual edition of the graph produced - if (requireNamespace("ggplot2", quietly = TRUE)){ - g1<-get("g1",envir=envir_stacomi) - g1<-g1+ggplot2::ggtitle("Les Enfrenaux")+ - ggplot2::scale_fill_manual(name="Source", - values=c("purple","#0A0C01"), - labels = c("historical set","2015 values"))+ - ggplot2::scale_colour_manual(name="Source", values="#B8EA00", - labels = c("historical mean")) + - ggplot2::ylab("Nombre d'anguilles") - print(g1) - } - ######################################################### +if (requireNamespace("ggplot2", quietly = TRUE)) { + g1 <- get("g1", envir = envir_stacomi) + g1 <- g1 + ggplot2::ggtitle("Les Enfrenaux") + + ggplot2::scale_fill_manual( + name = "Source", + values = c("purple", "#0A0C01"), + labels = c("historical set", "2015 values") + ) + + ggplot2::scale_colour_manual( + name = "Source", values = "#B8EA00", + labels = c("historical mean") + ) + + ggplot2::ylab("Nombre d'anguilles") + print(g1) +} +######################################################### # Another graph to show a "manual" processing of the data # and their extraction from the data slot - ######################################################### - if (requireNamespace("ggplot2", quietly = TRUE)& - requireNamespace("viridis", quietly = TRUE)){ - dat<-fun_date_extraction(r_mig_interannual@data, # data to import - "bjo_jour", # name of the column where dates are found - annee=FALSE, - mois=TRUE, - semaine =TRUE, - jour_mois=FALSE) -# sum per month - res<-dplyr::select(dat,bjo_valeur,bjo_annee,semaine) - res<-dplyr::group_by(res,bjo_annee,semaine) - res<-dplyr::summarize(res,effectif=sum(bjo_valeur)) - ggplot2::ggplot(res, ggplot2::aes(x = semaine, y = bjo_annee,fill=effectif)) + - ggplot2::geom_tile(colour="black") + ggplot2::coord_fixed() + - viridis::scale_fill_viridis(begin=0,option="D") + ggplot2::theme_bw()+ - ggplot2::theme(panel.background= ggplot2::element_rect(fill = "#9360A9"), - panel.grid.major=ggplot2::element_line(colour="#C1DB39"), - panel.grid.minor=ggplot2::element_line(colour="#7DD632"))+ - ggplot2::ylab("year")+ggplot2::xlab("week")+ - ggplot2::ggtitle("Historical trend at Les Enfrenaux Eel trap") - - } - ############################################### +######################################################### +if (requireNamespace("ggplot2", quietly = TRUE) & + requireNamespace("viridis", quietly = TRUE)) { + dat <- fun_date_extraction(r_mig_interannual@data, # data to import + "bjo_jour", # name of the column where dates are found + annee = FALSE, + mois = TRUE, + semaine = TRUE, + jour_mois = FALSE + ) + # sum per month + res <- dplyr::select(dat, bjo_valeur, bjo_annee, semaine) + res <- dplyr::group_by(res, bjo_annee, semaine) + res <- dplyr::summarize(res, effectif = sum(bjo_valeur)) + ggplot2::ggplot(res, ggplot2::aes(x = semaine, y = bjo_annee, fill = effectif)) + + ggplot2::geom_tile(colour = "black") + + ggplot2::coord_fixed() + + viridis::scale_fill_viridis(begin = 0, option = "D") + + ggplot2::theme_bw() + + ggplot2::theme( + panel.background = ggplot2::element_rect(fill = "#9360A9"), + panel.grid.major = ggplot2::element_line(colour = "#C1DB39"), + panel.grid.minor = ggplot2::element_line(colour = "#7DD632") + ) + + ggplot2::ylab("year") + + ggplot2::xlab("week") + + ggplot2::ggtitle("Historical trend at Les Enfrenaux Eel trap") +} +############################################### # barchart with different splitting periods # the migration is displayed against seasonal data # extacted from all other years loaded in the report - ################################################ +################################################ # available arguments for timesplit are "quinzaine" and "mois" and "semaine" # with the silent=TRUE argument, it's always the latest year that is selected, # otherwise the user is prompted with a choice, to select the year he wants # to compare will all others... - plot(r_mig_interannual,plot.type="barchart",timesplit="quinzaine",year_choice=2015,silent=TRUE) -# Comparison with historical values. Each year and 2 weeks values +plot( + r_mig_interannual, + plot.type = "barchart", + timesplit = "quinzaine", + year_choice = 2015, + silent = TRUE +) +# Comparison with historical values. Each year and 2 weeks values # is a point on the graph... - plot(r_mig_interannual,plot.type="pointrange",timesplit="mois",year_choice=2015,silent=TRUE) - ############################################### +plot( + r_mig_interannual, + plot.type = "pointrange", + timesplit = "mois", + year_choice = 2015, + silent = TRUE +) +############################################### # Step plot # different years shown in the graph # the current year (or the selected year if silent=FALSE) # is displayed with a dotted line - ################################################ - plot(r_mig_interannual,plot.type="step",year_choice=2015,silent=TRUE) - if (requireNamespace("ggplot2", quietly = TRUE)& - requireNamespace("viridis", quietly = TRUE)){ - g<-get("g",envir=envir_stacomi) + ggplot2::theme_minimal() - g+viridis::scale_color_viridis(discrete=TRUE)+ - ggplot2::ggtitle("Cumulated migration step plot +################################################ +plot(r_mig_interannual, plot.type = "step", year_choice = 2015, silent = TRUE) +if (requireNamespace("ggplot2", quietly = TRUE) & + requireNamespace("viridis", quietly = TRUE)) { + g <- get("g", envir = envir_stacomi) + ggplot2::theme_minimal() + g + viridis::scale_color_viridis(discrete = TRUE) + + ggplot2::ggtitle("Cumulated migration step plot at les Enfrenaux eel trap") - - } - ############################################### +} +############################################### # Plots for seasonality of the salmon migration # using a Loire river dataset (Vichy fishway) - ################################################ - data("r_mig_interannual_vichy") +################################################ +data("r_mig_interannual_vichy") # the following show how data are processed to get # statistics for seaonal migration, daily values - r_mig_interannual_vichy<-calcule(r_mig_interannual_vichy, - timesplit="jour",year_choice=2012,silent=TRUE) -#r_mig_interannual_vichy@calcdata #check this to see the results +r_mig_interannual_vichy <- calcule(r_mig_interannual_vichy, + timesplit = "jour", year_choice = 2012, silent = TRUE +) +# r_mig_interannual_vichy@calcdata #check this to see the results # statistics for seaonal migration, weekly values - r_mig_interannual_vichy<-calcule(r_mig_interannual_vichy,timesplit="semaine" - ,year_choice=2012,silent=TRUE) -#r_mig_interannual_vichy@calcdata - +r_mig_interannual_vichy <- calcule(r_mig_interannual_vichy, + timesplit = "semaine", + year_choice = 2012, silent = TRUE +) +# r_mig_interannual_vichy@calcdata + # the plot method also runs the calcule method - plot(r_mig_interannual_vichy,plot.type="seasonal", - timesplit="semaine", year_choice=2012, silent=TRUE) - plot(r_mig_interannual_vichy,plot.type="seasonal", - timesplit="mois", year_choice=2012, silent=TRUE) - plot(r_mig_interannual_vichy,plot.type="seasonal", - timesplit="jour",year_choice=2012, silent=TRUE) - - - ############################################### +plot(r_mig_interannual_vichy, + plot.type = "seasonal", + timesplit = "semaine", year_choice = 2012, silent = TRUE +) +plot(r_mig_interannual_vichy, + plot.type = "seasonal", + timesplit = "mois", year_choice = 2012, silent = TRUE +) +plot(r_mig_interannual_vichy, + plot.type = "seasonal", + timesplit = "jour", year_choice = 2012, silent = TRUE +) + + +############################################### # Plots for seasonality using another Loire river dataset -# with the migration of Lampreys (Petromyzon marinus) +# with the migration of Lampreys (Petromyzon marinus) # recorded at the the Descarte DF (Vienne) - ################################################ +################################################ # run this only if you are connected to the logrami dataset -stacomi(database_expected = TRUE, sch = 'logrami') - bmi_des<-new("report_mig_interannual") - bmi_des<-choice_c(bmi_des, - dc=c(23), - taxa=c("Petromyzon marinus"), - stage=c("5"), - start_year="2007", - end_year="2014", - silent=TRUE) - bmi_des<-connect(bmi_des) - bmi_des<-calcule(bmi_des,timesplit="semaine") - plot(bmi_des,plot.type="seasonal",timesplit="semaine",year_choice=2014) - plot(bmi_des,plot.type="seasonal",timesplit="jour",year_choice=2014) - plot(bmi_des,plot.type="seasonal",timesplit="mois",year_choice=2014) -} - - - +stacomi(database_expected = TRUE, sch = "logrami") +bmi_des <- new("report_mig_interannual") +bmi_des <- choice_c(bmi_des, + dc = c(23), + taxa = c("Petromyzon marinus"), + stage = c("5"), + start_year = "2007", + end_year = "2014", + silent = TRUE +) +bmi_des <- connect(bmi_des) +bmi_des <- calcule(bmi_des, timesplit = "semaine") +plot(bmi_des, plot.type = "seasonal", timesplit = "semaine", year_choice = 2014) +plot(bmi_des, plot.type = "seasonal", timesplit = "jour", year_choice = 2014) +plot(bmi_des, plot.type = "seasonal", timesplit = "mois", year_choice = 2014) +} } \seealso{ Other report Objects: diff --git a/man/report_mig_mult-class.Rd b/man/report_mig_mult-class.Rd index 0fbd9daf61c280eed565c6acd100ac63ba38e17d..c9c5e0af894c135cf6925ade8612997435cf56e7 100644 --- a/man/report_mig_mult-class.Rd +++ b/man/report_mig_mult-class.Rd @@ -51,7 +51,7 @@ stacomi(database_expected=FALSE) ## launches the application in the command line ## here an example of loading ## the following lines will only run if you have the program installed -## and the iav scheme available in the database +## and the test scheme available in the database ## this example generates the r_mig_mult dataset # prompt for user and password but you can set appropriate options for host, port and dbname \dontrun{ @@ -122,6 +122,8 @@ plot(r_mig_mult,plot.type="standard",silent=TRUE) # Combined plot for ggplot2 plot(r_mig_mult,plot.type="multiple",silent=TRUE) + + plot(r_mig_mult,plot.type="time",silent=TRUE) # Data will be written in the data directory specified in # the datawd argument to stacomi, default "~" summary(r_mig_mult,silent=FALSE) diff --git a/man/report_sample_char-class.Rd b/man/report_sample_char-class.Rd index 65f9fbac4881bd783efc991597121dcd2be40b03..08acf26c12bcdb633d3ca87f4f7d303a6fe77d82 100644 --- a/man/report_sample_char-class.Rd +++ b/man/report_sample_char-class.Rd @@ -42,96 +42,103 @@ of the view vue_lot_ope_car stacomi( database_expected=FALSE) # If you have a working database # the following line of code will create the r_sample_char -# dataset from the iav (default) schema in the database +# dataset from the test (default) schema in the database \dontrun{ - stacomi(database_expected=TRUE) # uses default option sch = 'iav' - # prompt for user and password, you can set these in the options, - # including dbname and host - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) + stacomi(database_expected = TRUE) # uses default option sch = 'test' + # prompt for user and password, you can set these in the options, + # including dbname and host + if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } + } + options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password + ) #create an instance of the class r_sample_char <- new("report_sample_char") - # the following will load data for size, + # the following will load data for size, # parameters 1786 (total size) C001 (size at video control) # dc 5 and 6 are fishways located on the Arzal dam # two stages are selected - r_sample_char <- choice_c(r_sample_char, - dc=c(5,6), - taxa=c("Anguilla anguilla"), - stage=c("AGJ","CIV"), - par=c(1785,1786,1787,"C001"), - horodatedebut="2013-01-01", - horodatefin="2013-12-31", - silent=FALSE) + r_sample_char <- choice_c( + r_sample_char, + dc = c(5, 6), + taxa = c("Anguilla anguilla"), + stage = c("AGJ", "CIV"), + par = c(1786, "C001"), + horodatedebut = "2013-01-01", + horodatefin = "2013-12-31", + silent = FALSE + ) # two warning produced, ignored if silent=TRUE r_sample_char <- connect(r_sample_char) - r_sample_char <- calcule(r_sample_char,silent=TRUE) + r_sample_char <- calcule(r_sample_char, silent = TRUE) -} +} # load the dataset generated by previous lines data("r_sample_char") # A "violin" plot -plot(r_sample_char,plot.type="1",silent=TRUE) +plot(r_sample_char, plot.type = "1", silent = TRUE) # get the plot from envir_stacomi to change labels for name # if you use require(ggplot2) the :: argument is not needed # e.g. write require(ggplot2);g<-get("g",envir=envir_stacomi) # g+xlab("size")+ylab("year") -if (requireNamespace("ggplot2", quietly = TRUE)){ - g<-get("g",envir=envir_stacomi) - g+ggplot2::xlab("size")+ggplot2::ylab("year") +if (requireNamespace("ggplot2", quietly = TRUE)) { + g1 <- get("g1", envir = envir_stacomi) + g1 + ggplot2::xlab("size") + ggplot2::ylab("year") } -# A boxplot per month -plot(r_sample_char,plot.type="2",silent=TRUE) -# A xyplot -plot(r_sample_char,plot.type="3",silent=TRUE) +# A boxplot per month (named g2 in envir_stacomi) +plot(r_sample_char, plot.type = "2", silent = TRUE) +# A xyplot (named g3 in envir_stacomi) +plot(r_sample_char, plot.type = "3", silent = TRUE) \dontrun{ ##################################### -# an example graph created manually from data + # an example graph created manually from data ##################################### -# two variables one on DC, one on stage -# passing dc information to the stage variable - r_sample_char@data$std_libelle[r_sample_char@data$ope_dic_identifiant==5]<- - "Yellow eel (vert. slot fishway)" - r_sample_char@data$std_libelle[r_sample_char@data$std_libelle=="Anguille jaune"]<- - "Yellow eel (ramp)" - r_sample_char@data$std_libelle[r_sample_char@data$std_libelle=="civelle"]<- - "Glass eel (ramp)" -# creating a boxplot with custom output : an example -# again if you use require(ggplot2) the :: argument is not needed + # two variables one on DC, one on stage + # passing dc information to the stage variable + r_sample_char@data$std_libelle[r_sample_char@data$ope_dic_identifiant == + 5] <- + "Yellow eel (vert. slot fishway)" + r_sample_char@data$std_libelle[r_sample_char@data$std_libelle == "Anguille jaune"] <- + "Yellow eel (ramp)" + r_sample_char@data$std_libelle[r_sample_char@data$std_libelle == "civelle"] <- + "Glass eel (ramp)" + # creating a boxplot with custom output : an example + # again if you use require(ggplot2) the :: argument is not needed - if (requireNamespace("ggplot2", quietly = TRUE)){ - g<-ggplot2::ggplot(r_sample_char@data)+ - ggplot2::geom_boxplot(ggplot2::aes(x=annee, - y =car_valeur_quantitatif, - fill = std_libelle))+ - ggplot2::xlab("size")+ggplot2::ylab("year")+ - ggplot2::scale_fill_manual("stage & fishway", - values=c("Yellow eel (vert. slot fishway)"="blue", - "Yellow eel (ramp)"="turquoise3", - "Glass eel (ramp)"="Cyan"))+ - ggplot2::theme_bw() - print(g) + if (requireNamespace("ggplot2", quietly = TRUE)) { + g <- ggplot2::ggplot(r_sample_char@data) + + ggplot2::geom_boxplot( + ggplot2::aes(x = annee, y = car_valeur_quantitatif, fill = std_libelle) + ) + + ggplot2::xlab("size") + ggplot2::ylab("year") + + ggplot2::scale_fill_manual( + "stage & fishway", + values = c( + "Yellow eel (vert. slot fishway)" = "blue", + "Yellow eel (ramp)" = "turquoise3", + "Glass eel (ramp)" = "Cyan" + ) + ) + + ggplot2::theme_bw() + print(g) } -# get a simple summary using Hmisc::describe + # get a simple summary using Hmisc::describe summary(r_sample_char) -# get the command line to create the object using choice_c -# when the graphical interface has been used + # get the command line to create the object using choice_c + # when the graphical interface has been used print(r_sample_char) } } diff --git a/man/report_sea_age-class.Rd b/man/report_sea_age-class.Rd index f73b724a94c0babd7b77b523cc2adeef95c0a937..6e809b172e65369072dbc40f83fc3c3f0f15947f 100644 --- a/man/report_sea_age-class.Rd +++ b/man/report_sea_age-class.Rd @@ -48,63 +48,65 @@ This class is displayed by interface_report_sea_age \examples{ require(stacomiR) -stacomi( - database_expected=FALSE) +stacomi(database_expected = FALSE) # If you have a working database -# the following line of code will create the r_seaa dataset +# the following line of code will create the r_seaa dataset # from the logrami schema in the database \dontrun{ - stacomi(database_expected=TRUE, sch='logrami') - # overrides the default option sch = 'iav' - # prompt for user and password, you can set these in the options, - # including dbname and host - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) + stacomi(database_expected = TRUE, sch = 'test') + # prompt for user and password, you can set these in the options, + # including dbname and host + if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } + } + options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password + ) #create an instance of the class - r_seaa<-new("report_sea_age") - r_seaa<-choice_c(r_seaa, - dc=c(107,108,101), - horodatedebut="2012-01-01", - horodatefin="2012-12-31", - limit1hm=675, - limit2hm=875, - silent=FALSE + r_seaa <- new("report_sea_age") + r_seaa <- choice_c( + r_seaa, + dc = c(19, 20), + horodatedebut = "2012-01-01", + horodatefin = "2012-12-31", + stage = c('5'), + par = c('C001', 'A124'), + limit1hm = 675, + limit2hm = 875, + silent = FALSE ) - r_seaa<-connect(r_seaa) - r_seaa<-calcule(r_seaa) + r_seaa <- connect(r_seaa) + r_seaa <- calcule(r_seaa) -} +} # load the dataset generated by previous lines # Salmons from the loire on two dams data("r_seaa") # the calculation will fill the slot calcdata -# stages are in r_seaa@calcdata[["6"]][,"stage"] +# stages are in r_seaa@calcdata[["6"]][,"stage"] #look at data structure using str(r_seaa@calcdata[["6"]]) # plot data to confirm the split by limits is correct -plot(r_seaa, plot.type=1) +plot(r_seaa, plot.type = 1) # if there are several dc, data it split by dc -plot(r_seaa, plot.type=2) +plot(r_seaa, plot.type = 2) \dontrun{ -# print a summary statistic, and save the output in a list for later use - stats<-summary(r_seaa) + # print a summary statistic, and save the output in a list for later use + stats <- summary(r_seaa) write_database(r_seaa) } + } \seealso{ Other report Objects: diff --git a/man/report_silver_eel-class.Rd b/man/report_silver_eel-class.Rd index b09fe4f9a0c17959d2928014345469155c8e761c..1b5a16493ce2457163f0e798be67e25c3131cf6a 100644 --- a/man/report_silver_eel-class.Rd +++ b/man/report_silver_eel-class.Rd @@ -48,64 +48,66 @@ This class is displayed by interface_report_silver_eel \examples{ # launching stacomi without selecting the scheme or interface -stacomi( database_expected=FALSE) +stacomi(database_expected = FALSE) # the following script will load data from the two Anguillere monitored in the Somme # If you have a working database -# the following line of code will create the r_silver dataset +# the following line of code will create the r_silver dataset # from the "fd80." schema in the database \dontrun{ - stacomi(database_expected=TRUE, sch="fd80.") # overrides the default option sch = 'iav' - # prompt for user and password, you can set these in the options, - # including dbname and host - if (interactive()){ - if (!exists("user")){ - user <- readline(prompt="Enter user: ") - password <- readline(prompt="Enter password: ") - } - } - options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host ="localhost", - stacomiR.port = "5432", - stacomiR.user = user, - stacomiR.user = password - ) - + stacomi(database_expected = TRUE, sch = "fd80.") # overrides the default option sch = 'iav' + # prompt for user and password, you can set these in the options, + # including dbname and host + if (interactive()) { + if (!exists("user")) { + user <- readline(prompt = "Enter user: ") + password <- readline(prompt = "Enter password: ") + } + } + options( + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = "localhost", + stacomiR.port = "5432", + stacomiR.user = user, + stacomiR.user = password + ) + #create an instance of the class - r_silver<-new("report_silver_eel") - r_silver<-choice_c(r_silver, - dc=c(2,6), - horodatedebut="2010-09-01", - horodatefin="2016-10-04", - silent=FALSE) - r_silver<-connect(r_silver) -} + r_silver <- new("report_silver_eel") + r_silver <- choice_c( + r_silver, + dc = c(2, 6), + horodatedebut = "2010-09-01", + horodatefin = "2016-10-04", + silent = FALSE + ) + r_silver <- connect(r_silver) +} # load the dataset generated by previous lines data("r_silver") # the calculation will fill the slot calcdata -r_silver<-calcule(r_silver) -# stages are in r_silver@calcdata[["6"]][,"stage"] +r_silver <- calcule(r_silver) +# stages are in r_silver@calcdata[["6"]][,"stage"] #look at data structure using str(r_silver@calcdata[["6"]]) # standard plot as drawn by Laurent Beaulaton (Analyse des donnees d'argenture acquises en France) # showing Durif's stage according to size and eye diameter -plot(r_silver, plot.type=1) +plot(r_silver, plot.type = 1) # number per month or year and Durif's stage (year if number of dc >1) -plot(r_silver, plot.type="2") +plot(r_silver, plot.type = "2") # plot showing fulton's coefficient, and size weight graphs -# inspired from Acou et al., 2009 +# inspired from Acou et al., 2009 # Differential Production and Condition Indices of Premigrant # Eels in Two Small Atlantic Coastal Catchments # of France -plot(r_silver, plot.type="3") +plot(r_silver, plot.type = "3") # get a list of summary data and print output to screen -plot(r_silver, plot.type="4") +plot(r_silver, plot.type = "4") # print a summary statistic, and save the output in a list for later use -stats<-summary(r_silver) +stats <- summary(r_silver) } \seealso{ Other report Objects: diff --git a/man/report_species-class.Rd b/man/report_species-class.Rd index a396d610e2df28495de6884cb42edc0a8f73ef4e..d25295e374068a23206623a3ed2fd519f27efbfb 100644 --- a/man/report_species-class.Rd +++ b/man/report_species-class.Rd @@ -36,53 +36,60 @@ year/week/month. \examples{ # launching stacomi without selecting the scheme or interface -stacomi( database_expected=FALSE) -# the following script will load data +stacomi(database_expected = FALSE) +# the following script will load data # from the two Anguillere monitored in the Somme # If you have a working database -# the following line of code will create the bilesp dataset from the "iav." +# the following line of code will create the bilesp dataset from the "test." # schema in the database \dontrun{ - bilesp<-new("report_species") + bilesp <- new("report_species") # split is one of "none", "year", "week", "month - bilesp<-choice_c(bilesp, - dc=c(5,6,12), - split="year", - start_year="2008", - end_year="2012", - silent=FALSE) + bilesp <- choice_c( + bilesp, + dc = c(5, 6, 12), + split = "year", + start_year = "2009", + end_year = "2012", + silent = FALSE + ) bilesp <- connect(bilesp) bilesp <- calcule(bilesp) - plot(bilesp, plot.type="pie", silent=FALSE) - plot(bilesp, plot.type="barplot", silent=FALSE) - bilesp <- choice_c(bilesp, - dc=c(5,6,12), - split="month", - start_year="2015", - end_year="2016", - silent=FALSE) + plot(bilesp, plot.type = "pie", silent = FALSE) + plot(bilesp, plot.type = "barplot", silent = FALSE) + bilesp <- choice_c( + bilesp, + dc = c(5, 6, 12), + split = "month", + start_year = "2009", + end_year = "2012", + silent = FALSE + ) bilesp <- charge(bilesp) bilesp <- connect(bilesp) - plot(bilesp, plot.type="pie", silent=FALSE) - plot(bilesp, plot.type="barplot", silent=FALSE) + bilesp <- calcule(bilesp) + plot(bilesp, plot.type = "pie", silent = FALSE) + plot(bilesp, plot.type = "barplot", silent = FALSE) #length(unique(bilesp@calcdata$taxa_stage)) # 15 # here creating a vector of length 15 with nice blending colours - if (requireNamespace("grDevices", quietly = TRUE)) { - mycolorrampblue <- - grDevices::colorRampPalette(c("#395B74", "#010F19")) - mycolorrampyellow <- - grDevices::colorRampPalette(c("#B59C53", "#271D00")) - mycolorrampred <- - grDevices::colorRampPalette(c("#B56F53", "#270B00")) - color<-c(mycolorrampblue(5), - mycolorrampyellow(5), - mycolorrampred(5)) - plot(bilesp,plot.type="barplot",color=color,silent=TRUE) - } + if (requireNamespace("grDevices", quietly = TRUE)) { + mycolorrampblue <- + grDevices::colorRampPalette(c("#395B74", "#010F19")) + mycolorrampyellow <- + grDevices::colorRampPalette(c("#B59C53", "#271D00")) + mycolorrampred <- + grDevices::colorRampPalette(c("#B56F53", "#270B00")) + color <- c(mycolorrampblue(3), + mycolorrampyellow(3), + mycolorrampred(4)) + plot(bilesp, + plot.type = "barplot", + color = color, + silent = TRUE) + } summary(bilesp) -} - +} } \seealso{ Other report Objects: diff --git a/man/stacomi.Rd b/man/stacomi.Rd index 8da21063fbeb72b737e06bb268325b5837c3858b..0acdcebe28ab4cdb9cbe9e279f302055f15c2c3b 100644 --- a/man/stacomi.Rd +++ b/man/stacomi.Rd @@ -4,7 +4,7 @@ \alias{stacomi} \title{stacomi Main launcher for program stacomi} \usage{ -stacomi(database_expected=TRUE, datawd = "~", sch = "test") +stacomi(database_expected=TRUE, datawd = tempdir(), sch = "test") } \arguments{ \item{database_expected}{Boolean, if \code{TRUE} pre launch tests will be run to test the connection validity} @@ -22,23 +22,23 @@ To change the language use Sys.setenv(LANG = 'fr') or Sys.setenv(LANG = 'en') } \examples{ - require(stacomiR) -#launch stacomi - \dontrun{ -stacomi(database_expected=TRUE, datawd='~',sch= "iav") +require(stacomiR) +# launch stacomi +\dontrun{ +stacomi(database_expected = TRUE, datawd = tempdir(), sch = "iav") } # launch stacomi without connection to the database -stacomi(database_expected=FALSE) +stacomi(database_expected = FALSE) # launch stacomi with options options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host = readline(prompt = "Enter host: "), - stacomiR.port = "5432", - stacomiR.user = readline(prompt = "Enter user: "), - stacomiR.password = readline(prompt = "Enter password: ") + stacomiR.dbname = "bd_contmig_nat", + stacomiR.host = readline(prompt = "Enter host: "), + stacomiR.port = "5432", + stacomiR.user = readline(prompt = "Enter user: "), + stacomiR.password = readline(prompt = "Enter password: ") ) # another usefull option to print all queries run by stacomiR to the console - options('stacomiR.printqueries'= TRUE) +options("stacomiR.printqueries" = TRUE) } \author{ Cedric Briand \email{cedric.briand@eptb-vilaine.fr} diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index f9ee6899ac8263b9494be6e67f39b5925dd432ca..b07e1eb4c5b005f73655c5758a905abd07b32da8 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -3,13 +3,9 @@ # this file is called before testhat so funcion will be available in all test # https://testthat.r-lib.org/articles/test-fixtures.html#withr-defer- # could have used with_envvar and local_envvar but had to set them each time -options( - stacomiR.dbname = "bd_contmig_nat", - stacomiR.host = "localhost", - stacomiR.port = "5432", - stacomiR.user = "stacomi_test", - stacomiR.password = "stacomi_test" -) + +# options here for codecov + password <- getOption("stacomiR.password") # if not set will be "" dbname <- getOption("stacomiR.dbname") # if not set will be "" user <- getOption("stacomiR.user") diff --git a/tests/testthat/test-03-report_df.R b/tests/testthat/test-03-report_df.R index 06ed6b45e20693153bca26a2e50e085e0d78523e..bf4b0a40de41d71dbef692fe5df954bec59f1962 100644 --- a/tests/testthat/test-03-report_df.R +++ b/tests/testthat/test-03-report_df.R @@ -1,95 +1,99 @@ context("report_df") test_that("Test an instance of report_df", { - skip_on_cran() - stacomi(database_expected = FALSE, sch ="test") - env_set_test_stacomi() - r_df <- new("report_df") - r_df <- choice_c( - r_df, - 2, - horodatedebut = "2013-01-01", - horodatefin = "2013-12-31", - silent = TRUE - ) - expect_gt(nrow(r_df@df@data), - 0, - label = "There should be data loaded by the choice_c method in the data slot of - the ref_df slot,nrow(r_df@df@data)") - expect_s4_class(r_df, - "report_df") - expect_error( - BfDF <- choice_c( - r_df, - 2, - horodatedebut = "2013 01 011", - horodatefin = "2013-12-31", - silent = TRUE - ) - ) - rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) - - }) + skip_on_cran() + stacomi(database_expected = FALSE, sch = "test") + env_set_test_stacomi() + r_df <- new("report_df") + r_df <- choice_c( + r_df, + 2, + horodatedebut = "2013-01-01", + horodatefin = "2013-12-31", + silent = TRUE + ) + expect_gt(nrow(r_df@df@data), + 0, + label = "There should be data loaded by the choice_c method in the data slot of + the ref_df slot,nrow(r_df@df@data)" + ) + expect_s4_class( + r_df, + "report_df" + ) + expect_error( + BfDF <- choice_c( + r_df, + 2, + horodatedebut = "2013 01 011", + horodatefin = "2013-12-31", + silent = TRUE + ) + ) + rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) +}) test_that("report_df charge method works", { - skip_on_cran() - stacomi(database_expected = TRUE, sch ="test") - env_set_test_stacomi() - r_df <- new("report_df") - r_df <- choice_c( - r_df, - 2, - horodatedebut = "2013-01-01", - horodatefin = "2013-12-31", - silent = TRUE - ) - r_df <- charge(r_df, silent = TRUE) - r_df <- connect(r_df, silent = TRUE) - expect_equal(nrow(r_df@data), 5) - rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) - - }) + skip_on_cran() + stacomi(database_expected = TRUE, sch = "test") + env_set_test_stacomi() + r_df <- new("report_df") + r_df <- choice_c( + r_df, + 2, + horodatedebut = "2013-01-01", + horodatefin = "2013-12-31", + silent = TRUE + ) + r_df <- charge(r_df, silent = TRUE) + r_df <- connect(r_df, silent = TRUE) + expect_equal(nrow(r_df@data), 5) + rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) +}) test_that("report_df plot method works", { - stacomi(database_expected = FALSE, sch ="test") - data(r_df) - r_df <- r_df - # expect_error(expr,NA) tests for an absence of error - expect_no_error({ - invisible(capture.output(plot(r_df, plot.type = "1", silent = TRUE))) - invisible(capture.output(plot(r_df, - plot.type = "2", - silent = TRUE, - main = "An example title"))) - plot(r_df, - plot.type = "3", - silent = TRUE, - main = "An example title") - plot(r_df, - plot.type = "4", - silent = TRUE, - main = "An example title")}) - rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) - }) - + stacomi(database_expected = FALSE, sch = "test") + data(r_df) + r_df <- r_df + # expect_error(expr,NA) tests for an absence of error + expect_no_error({ + invisible(capture.output(plot(r_df, plot.type = "1", silent = TRUE))) + invisible(capture.output(plot(r_df, + plot.type = "2", + silent = TRUE, + main = "An example title" + ))) + plot(r_df, + plot.type = "3", + silent = TRUE, + main = "An example title" + ) + plot(r_df, + plot.type = "4", + silent = TRUE, + main = "An example title" + ) + }) + rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) +}) test_that("report_df summary method works", { - skip_on_cran() - stacomi(database_expected = FALSE, sch ="test") - data(r_df) - r_df <- r_df - #expected <- ifelse(Sys.getlocale(category = "LC_TIME")=="French_France.utf8", "statistiques", "summary") - expect_output(summary(r_df, silent = TRUE)) - rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) - }) + skip_on_cran() + stacomi(database_expected = FALSE, sch = "test") + data(r_df) + # r_df <- r_df + # expected <- ifelse(Sys.getlocale(category = "LC_TIME")=="French_France.utf8", "statistiques", "summary") + expect_output(summary(r_df, silent = TRUE)) + rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) +}) test_that("report_df print method works", { - skip_on_cran() - stacomi(database_expected = FALSE, sch ="test") - data(r_df) - r_df <- r_df - expect_output(print(r_df)) - rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) - }) \ No newline at end of file + skip_on_cran() + stacomi(database_expected = FALSE, sch = "test") + data(r_df) + r_df <- r_df + expect_output(print(r_df)) + rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) +}) diff --git a/tests/testthat/test-05-report_sample_char.R b/tests/testthat/test-05-report_sample_char.R index 87128d4391c6a1071de5f82cd8761854dd3d0f78..680d7f02c93697b8cdf2ca83f034b31c03328564 100644 --- a/tests/testthat/test-05-report_sample_char.R +++ b/tests/testthat/test-05-report_sample_char.R @@ -5,7 +5,7 @@ test_that("Test that view lot_ope_car exists", { stacomi(database_expected = TRUE, sch = "test") req <- new("RequeteDB") sch <- rlang::env_get(envir_stacomi, "sch") - req@sql <- paste("select * from ", sch, " vue_lot_ope_car limit 10") + req@sql <- paste("select * from ", sch, "vue_lot_ope_car limit 10") req <- stacomirtools::query(req) result <- req@query expect_true(nrow(result) > 0) @@ -80,8 +80,8 @@ test_that("Test charge method for report_sample_char", { taxa = c("Anguilla anguilla"), stage = c("AGJ", "CIV"), par = c(1785, 1786, 1787, "C001"), - horodatedebut = "2013-01-01", - horodatefin = "2013-12-31", + horodatedebut = "2009-01-01", + horodatefin = "2009-12-31", silent = TRUE ) ) diff --git a/vignettes/stacomir.R b/vignettes/stacomir.R deleted file mode 100644 index 5a35e1702fa2344cbe89305a9a741ff60813b7aa..0000000000000000000000000000000000000000 --- a/vignettes/stacomir.R +++ /dev/null @@ -1,105 +0,0 @@ -## ----setup, include = FALSE--------------------------------------------------- -require(knitr) -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "../man/figures/README-" -) -opts_knit$set(message=FALSE, warnings=FALSE,error=FALSE,include=FALSE) - -## ----echo=FALSE, include=FALSE------------------------------------------------ -library(stacomiR) - - -## ---- eval=FALSE-------------------------------------------------------------- -# # get the package from CRAN -# install.packages("stacomiR") -# # get the development version -# install.packages("stacomiR", repos="http://R-Forge.R-project.org") - -## ---- eval=FALSE-------------------------------------------------------------- -# stacomi() - -## ---- eval=FALSE-------------------------------------------------------------- -# #here is an example to connect with interactive use -# options( -# stacomiR.dbname = "bd_contmig_nat", -# stacomiR.host = readline(prompt = "Enter host: "), -# stacomiR.port = "5432", -# stacomiR.user = readline(prompt = "Enter user: "), -# stacomiR.password = readline(prompt = "Enter password: ") -# ) -# # the schema of connection is passed by sch -# stacomi(database_expected = TRUE, sch= "iav") - -## ---- eval=TRUE, echo=TRUE---------------------------------------------------- -## launches the application in the command line without connection to the database -stacomi(database_expected=FALSE) - -## ----eval=FALSE,echo=TRUE----------------------------------------------------- -# require(stacomiR) -# stacomi( -# database_expected=TRUE) -# r_mig_mult=new("report_mig_mult") -# r_mig_mult=choice_c(r_mig_mult, -# dc=c(5,6,12), -# taxa=c("Anguilla anguilla"), -# stage=c("AGG","AGJ","CIV"), -# datedebut="2011-01-01", -# datefin="2011-12-31") -# r_mig_mult<-charge(r_mig_mult) -# # launching charge will also load classes associated with the report -# # e.g. report_ope, report_df, report_dc -# r_mig_mult<-connect(r_mig_mult) -# # calculations -# r_mig_mult<-calcule(r_mig_mult,silent=TRUE) - -## ----rmmstd,eval=FALSE,echo=TRUE,message=FALSE,fig.height=6,fig.with=8-------- -# # Without a connection at the database we can launch these lines to generate the graph -# # To obtain titles in french use Sys.setenv(LANG = "fr") -# # the -# require(stacomiR) -# stacomi( -# database_expected=FALSE) -# data("r_mig_mult") -# data("r_mig_mult_ope") -# assign("report_ope",r_mig_mult_ope,envir=envir_stacomi) -# data("r_mig_mult_df") -# assign("report_df",r_mig_mult_df,envir=envir_stacomi) -# data("r_mig_mult_dc") -# assign("report_dc",r_mig_mult_dc,envir=envir_stacomi) -# # The two lines below avoid an error in MacOSX, the r_mig_mult currently has CET -# # which for some reason provides a failure when testing the vignette in MaxOSX (twice the same date in seq.POSIXt) -# attr(r_mig_mult@data$ope_date_debut, "tzone") <- "UTC" -# attr(r_mig_mult@data$ope_date_fin, "tzone") <- "UTC" -# r_mig_mult <- calcule(r_mig_mult,silent=TRUE) -# -# -# # restrict to glass eel -# r_mig_mult@stage@stage_selected <- r_mig_mult@stage@stage_selected[3] -# r_mig_mult@dc@dc_selected <- r_mig_mult@dc@dc_selected[3] -# r_mig_mult <- calcule(r_mig_mult,silent=TRUE) -# plot(r_mig_mult, plot.type="standard", silent=TRUE) - -## ----rmmmult,eval=TRUE,echo=TRUE,fig.height = 4, fig.width = 6---------------- - -plot(r_mig_mult,plot.type="multiple",silent=TRUE) - -## ----silver,eval=TRUE,echo=TRUE,message=FALSE,warning=FALSE,fig.height = 4, fig.width = 6,fig.keep="all"---- -require(stacomiR) -data("coef_durif") -# load a dataset of class report_silver_eel with data slot already prepared -# here is an example of output -data("r_silver") -r_silver <- calcule(r_silver) -plot(r_silver, plot.type="3") -####################################### -# To use the function fun_stage_durif manually -# create a matrix with columns BL","W","Dv","Dh","FL" -############################################# -# here it is extracted from the data at hand -silver_eel<-as.matrix(r_silver@calcdata[[1]][,c("BL","W","Dv","Dh","FL")]) -head(silver_eel) # to see the first lines -stage <- fun_stage_durif(silver_eel) # apply the function to the matrix -stage[1:10] # look at the first 10 elements in vector silver -