Closed LucieContamin closed 2 weeks ago
Unfortunately this whole part of work is stuck on this issue, the fact that it is not at all straightforward to write valid JSON from R primarily because R has no concept of scalars Vs arrays, all are vectors.
Some exploration of using the schema and jsonvalidate::json_serialise to determine what should be a scalar and what an array on JSON was attempted but that also threw unexpected errors with our configs/schemas. If this is to work eventually it will likely need non trivial upstream contribution to the jsonvalidate package but given other pressing priorities and that initial attempts showed the problem to be quite complex not sure when it might be tackled.
Yes that what I was wondering, I think it's OK to manually fix the JSON for now. I agree that it's not a priority. I was asking in case you had a quick solution, I will let you know if I found a quick solution!
So gutted that I don't have a better solution for you apart from indeed manually fixing the output 😫. I really hope we manage to resolve it at some point given the effort that went into the rest of the functionality. It just ended up a much more complex problem than I anticipated! 😭
If you do find a solution let me know for sure!!
Adding context from PR here:
In PR (#30) I added a write_config()
function for writing out config
class objects of programmatically created task configurations to JSON files.
It's been put off for some time because it's almost impossible to write a valid config file due to inconsistencies between R and JSON data types, in particular the fact that R has no concept of a scalar. As such some properties in the output file will likely not conform to schema expectations. They might be an
I tried to make use of the jsonvalidate::json_serialise()
functionality, which can help serialise R objects in a schema aware way but I gave up because:
jsonvalidate
javascript source code.
Error: TypeError: Cannot convert undefined or null to object
jsonvalidate::json_serialise()
has been for some time now (since last year) only available in the development version of jsonvalidate
with no indication when it might be pushed to CRAN.json_serialise()
cannot make use of oneOf
statements which we use in our schema.As such, I've added a warning in the docs about this as well as issuing a message on write, advising users of the pitfalls and directing to use validate_config()
to validate the config files written out and identify any deviations.
Is there a good way to write the
create_rounds()
output in a JSON file format that does not returns error because of formatting?See example below
hubUtils
config validation error report./hub-config/tasks.json
using schema version v2.0.0schema_version
properties └schema_version └─type
string
rounds └1 └─round_id_from_variable
properties └rounds └─items └──properties └───round_id_from_variable └────type
boolean
rounds └1 └─round_id
properties └rounds └─items └──properties └───round_id └────type
string
rounds └1 └─model_tasks └──1 └───task_ids └────origin_date └─────required
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────task_ids └───────properties └────────origin_date └─────────properties └──────────required └───────────type
array, null
rounds └1 └─model_tasks └──1 └───output_type └────mean └─────output_type_id
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────output_type └───────properties └────────mean └─────────properties └──────────output_type_id └───────────oneOf
1 required-description: When mean is required, property set to single element ‘NA’ array required-type: array required-items-const:‘NA’ required-items-maxItems: 1 optional-description: When mean is required, property set to null optional-type: null
2 required-description: When mean is optional, property set to null required-type: null optional-description: When mean is optional, property set to single element ‘NA’ array optional-type: array optional-items-const:‘NA’ optional-items-maxItems: 1
rounds └1 └─model_tasks └──1 └───output_type └────mean └─────value └──────type
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────output_type └───────properties └────────mean └─────────properties └──────────value └───────────properties └────────────type └─────────────type
string
rounds └1 └─model_tasks └──1 └───output_type └────mean └─────value └──────minimum
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────output_type └───────properties └────────mean └─────────properties └──────────value └───────────properties └────────────minimum └─────────────type
number, integer
rounds └1 └─model_tasks └──1 └───target_metadata └────1 └─────target_id
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────target_metadata └───────items └────────properties └─────────target_id └──────────type
string
rounds └1 └─model_tasks └──1 └───target_metadata └────1 └─────target_name
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────target_metadata └───────items └────────properties └─────────target_name └──────────type
string
rounds └1 └─model_tasks └──1 └───target_metadata └────1 └─────target_units
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────target_metadata └───────items └────────properties └─────────target_units └──────────type
string
rounds └1 └─model_tasks └──1 └───target_metadata └────1 └─────target_type
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────target_metadata └───────items └────────properties └─────────target_type └──────────type
string
rounds └1 └─model_tasks └──1 └───target_metadata └────1 └─────is_step_ahead
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────target_metadata └───────items └────────properties └─────────is_step_ahead └──────────type
boolean
rounds └1 └─model_tasks └──1 └───target_metadata └────1 └─────time_unit
properties └rounds └─items └──properties └───model_tasks └────items └─────properties └──────target_metadata └───────items └────────properties └─────────time_unit └──────────type
string
rounds └1 └─submissions_due
properties └rounds └─items └──properties └───submissions_due └────oneOf
1 relative_to-description: Name of task id variable in relation to which submission start and end dates are calculated. relative_to-type: string start-description: Difference in days between start and origin date. start-type: integer start-format:‘NA’ end-description: Difference in days between end and origin date. end-type: integer end-format:‘NA’ required1: relative_to required2: start required3: end
2 relative_to-description:‘NA’ relative_to-type:‘NA’ start-description: Submission start date. start-type: string start-format: date end-description: Submission end date. end-type: string end-format: date required1: start required2: end
hubDocs
documentation.Created on 2023-11-03 with reprex v2.0.2