write.config.PEPRMT() errors when the event file has no supported events for the site

Open Beginner friendly
#4,255 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
backend

Research direction

Start in write.config.PEPRMT() and trace how supported events are filtered and sorted; the issue names this function but no source file or test path. Reproduce with an event list containing only planting, then add a focused regression test and confirm the run produces the same run_data.csv as a run with no events.

Written by the indexing model from the issue text.

Description

Summary

write.config.PEPRMT() keeps only the supported event types (salinity, elevation) and then sorts the remaining events by date:

evt_order <- sapply(evts, \(x) x$date) |> as.Date() |> order()

If no supported event remains, evts is an empty list, sapply() returns list(), and as.Date(list()) stops with an error.

When this happens

  • the site's events array is empty, or
  • every event is of a type PEPRMT does not use (for example only planting). The events JSON is shared between models, so a file with only other models' events is a realistic input.

Reproduction (on develop)

Run write.config.PEPRMT() with run$inputs$event_json pointing at

[{"site_id": "S1", "events": [{"event_type": "planting", "date": "2020-01-02"}]}]
INFO Ignoring unsupported event types 'planting'. Supported event types are: 'salinity', 'elevation'
Error in as.Date.default(sapply(evts, function(x) x$date)) :
  do not know how to convert 'sapply(evts, function(x) x$date)' to class "Date"

With no event input at all, or with a mix of supported and unsupported events, it works.

Proposed fix

Only sort when length(evts) > 0. The run then produces the same run_data.csv as a run with no events. I have a branch with a small test that fails on develop and passes with the fix; happy to send a PR if wanted

Dominant language
R
Stars
246
Forks
322
Avg merge
4d 15h
Merged PRs (30d)
15

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PecanProject/pecan

All issues in PecanProject/pecan

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.