kevinwolz / hisafer

An R toolbox for the Hi-sAFe biophysical agroforestry model
6 stars 4 forks source link

Error message using build_hisafe() : "Result 1 must be a single string, not NULL of length 0" #129

Closed Guillaume-Blanchet closed 5 years ago

Guillaume-Blanchet commented 5 years ago

Hi @kevinwolz ! I am trying to create 3 simulation folders for a calibration procedure by using the following command in R :

hip <- define_hisafe(path = getwd(), 
                     SimulationName = c("0_barley_original_plant_file", "0_winter_barley_original_plant_file", "0_winter_barley_2017_calib_plant_file"), 
                     profiles = "all", 
                     template = "./template_winter_barley_monocrop_A2",  # Template "template_winter_barley_monocrop_A2" was created before using copy_hisafe_template()
                     mainCropSpecies = c("proto_barley.plt","proto_winterbarley.plt", "proto_winterbarley_AUGUSTA_v1.plt")) # Files were added to the template as well

build_hisafe(hip = hip)

hip is correctly created, but I get an error message when I use the function build_hisafe() that I don't understand at all...

Error: Result 1 must be a single string, not NULL of length 0
Call `rlang::last_error()` to see a backtrace

Using rlang::last_error()gives that result :

> rlang::last_error()
<error>
message: Result 1 must be a single string, not NULL of length 0
class:   `purrr_error_bad_element_vector`
backtrace:
 1. hisafer::build_hisafe(hip = hip)
 7. purrr:::stop_bad_element_vector(...)
 8. purrr:::stop_bad_vector(...)
 9. purrr:::stop_bad_type(...)
Call `rlang::last_trace()` to see the full backtrace

Pushing it forward with rlang::last_trace results in :

rlang::last_trace()
    █
 1. ├─hisafer::build_hisafe(hip = hip)
 2. │ └─purrr::walk(...)
 3. │   └─purrr::map(.x, .f, ...)
 4. │     └─hisafer:::.f(.x[[i]], ...)
 5. │       └─hisafer:::read_param_file(i)
 6. │         └─purrr::map_chr(...)
 7. └─purrr:::stop_bad_element_vector(...)
 8.   └─purrr:::stop_bad_vector(...)
 9.     └─purrr:::stop_bad_type(...)

Any idea of what's wrong with the code I propose ? Many thanks in advance !

Guillaume-Blanchet commented 5 years ago

Any idea @mariegosme ?

mariegosme commented 5 years ago

Halleluja, I found the cause of the problem: something in the variety description was not working (or the end of file symbol was not the good one, or there was something corrupt at the end of the crop files). this works with the files I'll send you by email: default.exp <- define_hisafe(path = getwd(), SimulationName = c("0_barley_original_plant_file", "0_winter_barley_original_plant_file", "0_winter_barley_2017_calib_plant_file"), template = "./template_winter_barley_monocrop_A2", # Template "template_winter_barley_monocrop_A2" was created before using copy_hisafe_template() mainCropSpecies = c("proto_barley_AUGUSTA_v1_hisafe_format_modifvariete.plt", "proto_barley_hisafe_format_modifvariete.plt", "proto_barley_AUGUSTA_v1_hisafe_format_modifvariete.plt") ) build_hisafe(hip =default.exp)

mariegosme commented 5 years ago

@Guillaume-Blanchet can you close this issue?

kevinwolz commented 5 years ago

Whew! I'm glad you figured it out before I could even get to it! If you figure out what was wrong with the .PLT file, maybe we can add a check to build_hisafe() so it can provide a more informative error message.

mariegosme commented 5 years ago

I figured out what was wrong: it's just that the "title" introducing the cultivar parameters section was # VARIETIES instead of ## VARIETIES !! hours of headache for a simple # !

Guillaume-Blanchet commented 5 years ago

Well, apparently, the # character is not the only reason the files are not accepted. If I only add the # character (so that I get ## VARIETIES) to the files I had, then I got another error message :

> build_hisafe(hip = hip)
Error: Result 1 is not a length 1 atomic vector

NB : I also paid attention to the errors induced by your script (for STICS .plt file conversion toward Hi-sAFe .plt format) @mariegosme , especially when several varieties are present in the .plt file (such as the original file of proto_barley.plt, where two varieties are present). I had different lines for each variety...

mariegosme commented 5 years ago

That's strange: on my computer, when I take your original files (proto_barley_AUGUSTA_v1_hisafe_format proto_barley_hisafe_format proto_winterbarley_hisafe_format), and just change #Varietes into ## VARIETIES, it works (even leaving multilines varieties like c("cork", "scarlett") c("380.", "400.0") in proto_barley_hisafe_format, but I think this will cause problems when running the model). Does it work with the files I sent you by email?