API deployed to Connect producing locale error

I've built a model using tidymodels (an XGBoost model forecasting business event counts) and deployed it as a plumber API to Posit Connect (via vetiver). The API itself was deployed without error, however, when I try and get predictions from it, either in R or in the browser, it returns "500 - Internal server error". The API logs offer a little more detail:

<simpleError in Sys.setlocale("LC_TIME", locale): (converted from warning) OS reports request to set locale to "English_United Kingdom.utf8" cannot be honored>

The locale details in the API logs state: LANG: C.UTF-8, but using Sys.getlocale() to get my locale settings, I get the following:

 "LC_COLLATE=English_United Kingdom.utf8;LC_CTYPE=English_United Kingdom.utf8;LC_MONETARY=English_United Kingdom.utf8;LC_NUMERIC=C;LC_TIME=English_United Kingdom.utf8"

I did try specifying LC_ALL=C in .Renviron (it was a bit of a shot in the dark), but this didn't resolve the error.

The Connect server version is 1.8.6.2 and the Connect R version is 4.0.4. Finally, my sessionInfo() when I deploy the API:

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.utf8  LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] vetiver_0.1.8   workflows_1.1.2 tune_1.0.1      yardstick_1.1.0 parsnip_1.0.3   timetk_2.8.2    recipes_1.0.3  
 [8] rsample_1.1.0   ggplot2_3.4.0   dplyr_1.0.10   

loaded via a namespace (and not attached):
 [1] ggtext_0.1.2        fs_1.5.2            xts_0.12.2          lubridate_1.9.0     bit64_4.0.5        
 [6] DiceDesign_1.9      httr_1.4.4          tools_4.2.1         utf8_1.2.2          R6_2.5.1           
[11] rpart_4.1.19        DBI_1.1.3           colorspace_2.0-3    nnet_7.3-18         withr_2.5.0        
[16] tidyselect_1.2.0    bit_4.0.5           curl_4.3.3          compiler_4.2.1      cli_3.4.1          
[21] swagger_3.33.1      xml2_1.3.3          scales_1.2.1        readr_2.1.3         askpass_1.1        
[26] odbc_1.3.3          rappdirs_0.3.3      plumber_1.2.1       stringr_1.4.1       digest_0.6.30      
[31] webutils_1.1        pkgconfig_2.0.3     parallelly_1.32.1   lhs_1.1.5           rlang_1.0.6        
[36] rstudioapi_0.14     generics_0.1.3      zoo_1.8-11          jsonlite_1.8.3      vroom_1.6.0        
[41] magrittr_2.0.3      Matrix_1.5-3        Rcpp_1.0.9          munsell_0.5.0       fansi_1.0.3        
[46] GPfit_1.0-8         lifecycle_1.0.3     furrr_0.3.1         stringi_1.7.8       yaml_2.3.6         
[51] snakecase_0.11.0    MASS_7.3-58.1       grid_4.2.1          blob_1.2.3          promises_1.2.0.1   
[56] parallel_4.2.1      listenv_0.8.0       crayon_1.5.2        lattice_0.20-45     splines_4.2.1      
[61] gridtext_0.1.5      hms_1.1.2           pillar_1.8.1        dials_1.1.0         future.apply_1.10.0
[66] codetools_0.2-18    glue_1.6.2          packrat_0.8.1       renv_0.16.0         vctrs_0.5.1        
[71] tzdb_0.3.0          foreach_1.5.2       openssl_2.0.4       gtable_0.3.1        purrr_0.3.5        
[76] tidyr_1.2.1         future_1.29.0       pins_1.0.3          gower_1.0.0         janitor_2.1.0      
[81] prodlim_2019.11.13  later_1.3.0         rsconnect_0.8.28    class_7.3-20        survival_3.4-0     
[86] timeDate_4021.106   tibble_3.1.8        iterators_1.0.14    hardhat_1.2.0       lava_1.7.0         
[91] timechange_0.1.1    globals_0.16.2      ellipsis_0.3.2      ipred_0.9-13     

I'm a little bit stumped as to what to do to resolve this error, so I suspect that I'm also not giving all the relevant information that folks will need to help (though I've included everything that I thought might be useful). Let me know if anything is missing and I can update.

Any help would be greatly appreciated!

(converted from warning)

This tells me that the R warn options has been set to something different from the default value. It is required for your API to run properly?

So after some playing around and some suggestions from elsewhere, I was able to find a solution to the problem. I thought I'd share it here just in case someone else finds themselves here looking for something similar.

The issue appears to be driven by a mismatch in locale settings between Connect and my local machine, and it was being driven by a date column in the data. I found that specifying that the date column locale has to match my system locale was sufficient, as follows:

dplyr::mutate(date = lubridate::ymd(date, locale = Sys.getlocale("LC_TIME")))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.