32.4 Settings

  • A generic settings can be found in the PEcAn.all package
settings.xml <- system.file("pecan.biocro.xml", package = "PEcAn.BIOCRO")
settings <- read.settings(settings.xml)
  • database settings can be specified, and tests run only if a connection is available

We currently use the following database to run tests against; tests that require access to a database should check db.exists() and be skipped if it returns FALSE to avoid failed tests on systems that do not have the database installed.

settings$database <- list(userid = "bety", 
                          passwd = "bety", 
                          name = "bety",     # database name 
                          host = "localhost" # server name)
test_that(..., {
  skip_if_not(db.exists(settings$database))
  ## write tests here
})
  • instructions for installing this are available on the VM creation wiki

  • examples can be found in the PEcAn.DB package (base/db/tests/testthat/).

  • Model specific settings can go in the model-specific module, for example:

settings.xml <- system.file("extdata/pecan.biocro.xml", package = "PEcAn.BIOCRO")
settings <- read.settings(settings.xml)
  • test-specific settings:
    • settings text can be specified inline:

      settings.text <- "
        <pecan>
          <nocheck>nope</nocheck> ## allows bypass of checks in the read.settings functions
          <pfts>
            <pft>
              <name>ebifarm.pavi</name>
              <outdir>test/</outdir>
            </pft>
          </pfts>
          <outdir>test/</outdir>
          <database>
            <userid>bety</userid>
            <passwd>bety</passwd>
            <location>localhost</location>
            <name>bety</name>
          </database>
        </pecan>"
      settings <- read.settings(settings.text)
    • values in settings can be updated:

      settings <- read.settings(settings.text)
      settings$outdir <- "/tmp" ## or any other settings