How do I fix the “No encoding Supplied” error?
Andrew Mclaughlin
I am facing difficulties after running the code and trying to export the dataset to a spreadsheet or txt.file. I am newbie to R, so maybe this question is trivial.
After running the following code:
eia_series <- function(api_key, series_id, start = NULL, end = NULL, num = NULL, tidy_data = "no", only_data = FALSE){ # max 100 series # test if num is not null and either start or end is nut null. Not allowed # api_key test for character. # series_id test for character. # if start/end not null, then check if format matches series id date format # parse date and numerical data # parse url series_url <- httr::parse_url("") series_url$query$series_id <- paste(series_id, collapse = ";") series_url$query$api_key <- api_key series_url$query$start <- start series_url$query$end <- end series_url$query$num <- num # get data series_data <- httr::GET(url = series_url) series_data <- httr::content(series_data, as = "text") series_data <- jsonlite::fromJSON(series_data) # Move data from data.frame with nested list and NULL excisting series_data$data <- series_data$series$data series_data$series$data <- NULL # parse data series_data$data <- lapply(X = series_data$data, FUN = function(x) data.frame(date = x[, 1], value = as.numeric(x[, 2]), stringsAsFactors = FALSE)) # add names to the list with data names(series_data$data) <- series_data$data # parse dates series_data$data <- eia_date_parse(series_list = series_data$data, format_character = series_data$series$f) # tidy up data if(tidy_data == "tidy_long"){ series_data$data <- lapply(seq_along(series_data$data), function(x) {cbind(series_data$data[[x]], series_time_frame = series_data$series$f[x], series_name = series_data$series$series_id[x], stringsAsFactors = FALSE)})
series_data$data <- do.call(rbind, series_data$data) } # only data if(only_data){ series_data <- series_data$data } return(series_data)
}After running the function
eia_series(api_key = "XXX",series_id = c("PET.MCRFPOK1.M", "PET.MCRFPOK2.M"))I tried to "transfer" the data in order to export it but got the following error:
No encoding supplied: defaulting to UTF-8.
I don't understand why. Could you help me out?
12 Answers
That doesn't look like an error, rather a statement. Probably coming from httr::content(series_data, as = "text"). Look in in The body section. It shouldn't be a problem, as long as your data returns what you expect. Otherwise you can try different encoding or there is a bug elsewhere.
Try:
series_data <- httr::content(series_data, as = "text", encoding = "UTF-8")