Errors when trying to use View() on some objects

Hi -
I am getting this error and a blank tab when trying to View() certain list objects in Rstudio. I can print() the object and also expand it in the Environment pane, but it won't show up as a tab pane.
Error in is.na(output) || !is.character(output) :
'length = 3' in coercion to 'logical(1)'

Is no one else having this issue? Here is some code that will reproduce the error as long as you have a Census API key. When I View(response) I get an empty tab and this error:

Error in is.na(output) || !is.character(output) : 
  'length = 3' in coercion to 'logical(1)'
library(httr)
vars <- c("SEX","PWGTP","MAR")
region <- "public use microdata area:611"
regionin <- "state:25"
response <- getCensus("2021/acs/acs5/pums", vars = vars, region = region, regionin = regionin, show_call = TRUE)

query <- list(
  get = "SEX,PWGTP,MAR",
  `for` = "public use microdata area:611",
  `in` = "state:25",
  key = Sys.getenv("CENSUS_API_KEY")
)

response <- GET(
  url = "https://api.census.gov/data/2021/acs/acs5/pums",
  query = query
  )

View(response)

Trying again to get a response on this one as it is a very annoying bug. Here is an even simpler example. The code works fine, but when I try to View(response), it doesn't work, I just get an empty tab.

library(httr)

response <- GET(glue("https://data.cambridgema.gov/resource/sckh-3xyx.json"))
> response
Response [https://data.cambridgema.gov/resource/sckh-3xyx.json]
  Date: 2023-07-31 15:37
  Status: 200
  Content-Type: application/json;charset=utf-8
  Size: 411 kB
[{"dog_name":"Butch","dog_breed":"Mixed Breed","location_masked":{"type":"Point","coordinates":[-71.1328,42.3989]},"latitude_masked":"42.3989","longitude_m...
,{"dog_name":"Baxter","dog_breed":"Mixed Breed","location_masked":{"type":"Point","coordinates":[-71.1186,42.3814]},"latitude_masked":"42.3814","longitude_...
,{"dog_name":"Bodhi","dog_breed":"Golden Retriever","location_masked":{"type":"Point","coordinates":[-71.1308,42.3998]},"latitude_masked":"42.3998","longit...
,{"dog_name":"Ocean","dog_breed":"Pug","location_masked":{"type":"Point","coordinates":[-71.1087,42.3726]},"latitude_masked":"42.3726","longitude_masked":"...
,{"dog_name":"Coco","dog_breed":"Pug","location_masked":{"type":"Point","coordinates":[-71.1022,42.361]},"latitude_masked":"42.361","longitude_masked":"-71...
,{"dog_name":"Brio","dog_breed":"LABRADOODLE","location_masked":{"type":"Point","coordinates":[-71.1262,42.3892]},"latitude_masked":"42.3892","longitude_ma...
,{"dog_name":"Jolene Almeida","dog_breed":"German Shorthaired Pointer","location_masked":{"type":"Point","coordinates":[-71.0896,42.368]},"latitude_masked"...
,{"dog_name":"Ruger","dog_breed":"Labrador Retriever","location_masked":{"type":"Point","coordinates":[-71.1353,42.3932]},"latitude_masked":"42.3932","long...
,{"dog_name":"FLASH","dog_breed":"Border Collie","location_masked":{"type":"Point","coordinates":[-71.1305,42.3981]},"latitude_masked":"42.3981","longitude...
,{"dog_name":"Leo","dog_breed":"French Bulldog","location_masked":{"type":"Point","coordinates":[-71.1415,42.3902]},"latitude_masked":"42.3902","longitude_...
...
> View(response)
Error in is.na(output) || !is.character(output) : 
  'length = 3' in coercion to 'logical(1)'

I would say it's expected that View() doesn't work well for every single object type imaginable. Here, for an http response, there may not be a well-defined way to represent it. You want to get the content out before you do too much, for example, try this:

library(httr)
library(glue)

response <- GET(glue("https://data.cambridgema.gov/resource/sckh-3xyx.json"))

content(response, as = "text") |>
  jsonlite::fromJSON() |>
  View()

Hi - thanks for replying. The issue here is that I never used to have this problem (any object would show in View()) and it seems to be a bug in View() introduced by changes in R 4.3.0, just based on the error message. It used to be that calling "||" with a condition longer than one just gave a warning, not an error as is happening here, so something in View() needs to be updated to correct this. Sometimes it's convenient to see the entirety of the response, and not just the parsed content. Also, this problem occurs for other objects than requests with HTTR, that is just the example I had handy.
If this is intended behavior of View() then at the very least the error message should be more informative.

1 Like

Indeed, I think you are right. If I'm not mistaken, this is the same problem described in this GitHub issue.

1 Like

Yes, that is the same issue. Thanks for pointing me to that.

1 Like

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.