pfmc-assessments/nwfscSurvey

`fromJSON()` not working for R 4.3

kellijohnson-NOAA opened this issue · 1 comments

I am using the devel version of R on a Windows machine and jsonlite::fromJSON() thinks that the text string, which is a valid URL, is a file path and the functions below end up returning empty data frames and warning messages that the pulls cannot be completed as requested. I have written the following work around if the behaviour is not corrected before 4.3 is released. Regardless, we could implement the following function because it appears to be more robust than relying on just jsonlite::fromJSON()

get_json <- function(url) {
  out <- httr::GET(url) %>%
    httr::content(as = "text", encoding = "UTF-8") %>%
    jsonlite::fromJSON()
  if (!(is.data.frame(out) && NROW(out) > 0)) {
    stop(glue::glue("No data returned by the warehouse using {url}"))
  }
  return(out)
}

DataPull <- try(jsonlite::fromJSON(UrlText))

All.Tows <- jsonlite::fromJSON(UrlText)

bio_pull <- try(jsonlite::fromJSON(url_text))

len_pull <- try(jsonlite::fromJSON(url_text))

haul_data <- try(jsonlite::fromJSON(url_text))

positive_tows <- try(jsonlite::fromJSON(url_text))

all_tows <- jsonlite::fromJSON(url_text)

bio_samples <- try(jsonlite::fromJSON(url_text))

DataPull <- try(jsonlite::fromJSON(UrlText))

LenPull <- try(jsonlite::fromJSON(UrlText))

Data <- try(jsonlite::fromJSON(UrlText))