EnquistLab / RTNRS

R package for the (plant) Taxonomic Name Resolution Service
https://bien.nceas.ucsb.edu/bien/tools/tnrs/
Other
8 stars 0 forks source link

Unclear error when using input data.frame of more than 2 columns #13

Open Rekyt opened 1 year ago

Rekyt commented 1 year ago

Hi TNRS maintainers 👋

I really like the feature that let's the user submit a data.frame to the TNRS() function so that they can be easily referred in other contexts. However, I had a 3 columns data.frame that also included some additional info on the names, then the function output a strange error. I perfectly understand why TNRS() would only accept 2 columns data.frame and I have an easy fix for that, but maybe the error message could be clearer.

reprex:

# Works fine with a 2 columns dataset
TNRS::TNRS(data.frame(ID = 1, name = "Helianthus annuus"))
#>   ID    Name_submitted Overall_score Name_matched_id      Name_matched
#> 1  1 Helianthus annuus             1           51089 Helianthus annuus
#>   Name_score Name_matched_rank Author_submitted Author_matched Author_score
#> 1          1           species                                           NA
#>   Canonical_author Name_matched_accepted_family Genus_submitted Genus_matched
#> 1               L.                   Asteraceae      Helianthus    Helianthus
#>   Genus_score Specific_epithet_submitted Specific_epithet_matched
#> 1           1                     annuus                   annuus
#>   Specific_epithet_score Family_submitted Family_matched Family_score
#> 1                      1                                           NA
#>   Infraspecific_rank Infraspecific_epithet_matched Infraspecific_epithet_score
#> 1                                                                           NA
#>   Infraspecific_rank_2 Infraspecific_epithet_2_matched
#> 1                                                     
#>   Infraspecific_epithet_2_score Annotations Unmatched_terms
#> 1                            NA                            
#>                       Name_matched_url Name_matched_lsid Phonetic
#> 1 http://www.tropicos.org/Name/2700851                          Y
#>   Taxonomic_status     Accepted_name  Accepted_species Accepted_name_author
#> 1         Accepted Helianthus annuus Helianthus annuus                   L.
#>   Accepted_name_id Accepted_name_rank                    Accepted_name_url
#> 1            51089            species http://www.tropicos.org/Name/2700851
#>   Accepted_name_lsid Accepted_family Overall_score_order Highertaxa_score_order
#> 1                         Asteraceae                   1                      1
#>     Source Warnings
#> 1 tropicos        0

# Strange error message when having more than 2 columns
TNRS::TNRS(data.frame(ID = 1, name = "Helianthus annuus", other_name = "bla"))
#> Problem with the API: HTTP Status 400
#> NULL

Created on 2023-02-08 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.0 (2022-04-22 ucrt) #> os Windows 10 x64 (build 19045) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate fr_FR.UTF-8 #> ctype fr_FR.UTF-8 #> tz Europe/Berlin #> date 2023-02-08 #> pandoc 3.0.1 @ C:/Users/ke76dimu/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.6.0 2023-01-09 [1] CRAN (R 4.2.0) #> curl 5.0.0 2023-01-12 [1] CRAN (R 4.2.2) #> digest 0.6.31 2022-12-11 [1] CRAN (R 4.2.2) #> evaluate 0.20 2023-01-17 [1] CRAN (R 4.2.2) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> fs 1.6.0 2023-01-23 [1] CRAN (R 4.2.2) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> htmltools 0.5.4 2022-12-07 [1] CRAN (R 4.2.2) #> httr 1.4.4 2022-08-17 [1] CRAN (R 4.2.1) #> jsonlite 1.8.4 2022-12-06 [1] CRAN (R 4.2.2) #> knitr 1.42 2023-01-25 [1] CRAN (R 4.2.2) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> purrr 1.0.1 2023-01-10 [1] CRAN (R 4.2.2) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.1) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.0) #> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.1) #> rlang 1.0.6.9000 2022-10-11 [1] Github (r-lib/rlang@28a40b5) #> rmarkdown 2.20 2023-01-19 [1] CRAN (R 4.2.2) #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> styler 1.9.0 2023-01-15 [1] CRAN (R 4.2.2) #> TNRS 0.3.3 2023-01-11 [1] CRAN (R 4.2.2) #> vctrs 0.5.1 2022-11-16 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.36 2022-12-21 [1] CRAN (R 4.2.2) #> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.2.2) #> #> [1] C:/Users/ke76dimu/Documents/R/R-4.2.0/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
ojalaquellueva commented 1 year ago

@Rekyt An http status code from the API means a badly-formed request. @bmaitner please check the structure of the options and data elements of the JSON in the POST request. Also, I recommend returning a simple "Error: badly formed API call" when your code detects at http response of 400.