Skip to content

Pre-compiled Binaries for Easy Installation + Success with develop branch (15-arg signature) #12

@Aviteshmurmu19

Description

@Aviteshmurmu19

Hi Professor,

I saw the recent commits to the develop branch and wanted to confirm that the update to the 15-argument signature in rphydro_analytical successfully resolves the index_out_of_bounds / Object was created without names errors that occurred when using the master branch with the assignment script (that you provided us in moodle Tutorial 5 and 6).

While testing the updated develop version, I identified three small "traps" that might still cause crashes for other students. I've documented them here along with a revised phydro_ET wrapper that handles them:

1. The co2 Dataset Collision

Base R includes a built-in dataset called co2 (468 observations). In the simulation script, if a user accidentally comments out co2 = 400 or if R fails to find the local variable, it passes the 468-value dataset into the C++ function. Because C++ expects a single scalar, it throws a fatal error.

  • Recommendation: Rename the local variable to co2_ppm or co2_val inside the wrapper function.

2. VPD Unit Scaling (kPa vs Pa)

The simulation data provides VPD in kPa (e.g., 0.6), but the C++ physics engine in the develop branch expects Pascals (e.g., 600). Passing 0.6 Pa results in zero transpiration, while passing 800 kPa (from the original script's hardcoded value) causes the optimizer to fail.

  • Fix: Multiply vpd by 1000 before passing it to rphydro_analytical.

3. Night-time Stability (Negative PPFD)

Since Rn is negative at night, ppfd = Rn * 2 passes a negative value to the model, which can cause the internal solver to return a malformed list.

  • Fix: Use ppfd = max(Rn * 2, 0).

Revised phydro_ET Wrapper for the Develop Branch:

phydro_ET <- function(fapar, Rn, tc, vpd_kpa, psi_soil){
  kphio  = 0.04
  ppfd   = max(Rn * 2, 0)  # Guard against negative light
  co2_val = 400            # Avoid collision with base R 'co2' dataset
  elv    = 0
  rdark  = 0.015
  vwind  = 3
  pa     = calc_patm(elv)  # Returns Pa

  # Convert kPa to Pa for the C++ engine
  vpd_pa = vpd_kpa * 1000

  par_cost  = list(alpha = 0.1, gamma = 1)
  par_plant = list(conductivity = 3e-17, psi50 = -2, b = 2)
  opts      = list(gs_method = "GS_IGF", et_method = "ET_DIFFUSION", ...)

  # The 15-arg call matching the develop branch
  res = rphydro_analytical(tc, tc, ppfd, Rn, vpd_pa, co2_val, pa,
                           fapar, kphio, psi_soil, rdark, vwind,
                           par_plant, par_cost, opts)

  list(
    et = 1.6 * res$gs * (vpd_pa / pa) * 18.015e-3 * 86400,
    a  = res$a * 12.01e-3 * 86400 * 1e-3
  )
}

4. Pre-compiled Binaries for Easy Installation

I have compiled the develop branch into binaries for R 4.5.3 (or the current active version). If you'd like to add these to the repository's Releases page, students can bypass the compilation step entirely, which is especially helpful on Posit.cloud (due to 1GB RAM limits) or Windows (to avoid Rtools installation).

Files Attached:

Installation for Posit.cloud (Linux):

If you encounter a "Lock" error or need to reinstall, use this block:

# Clear any lock files and install from the tarball (you need to point to your specific directory, like this code block works on Posit.cloud)
unlink("/cloud/lib/x86_64-pc-linux-gnu-library/4.5/00LOCK-rphydro", recursive = TRUE)
untar("/cloud/project/rphydro_1.0_R4.5.3_x86_64_linux-gnu-develop.tar.gz", exdir = .libPaths()[1])
library(rphydro)

Installation for Local Windows Users:

Download the .zip file and run the following command. Note: In R, make sure to use forward slashes / or double backslashes \\ for the path:

# Change the path below to where you downloaded the file
install.packages("C:/Users/YourName/Downloads/rphydro_1.0_R4.5.3_x86_64_windows-develop.zip",
                 repos = NULL,
                 type = "win.binary")
library(rphydro)

Hope this feedback helps with the package rollout!

22B0366

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions