Skip to content

Error: Internal error in vec_slice_impl(): Unexpected NULL #5749

Closed
@leachandrew

Description

@leachandrew

This is a similar issue to that raised by #5189 that @hadley closed. Since that issue didn't have a reprex, and this is an issue which didn't previously exist using this code with this API, I think it's worth another look.

@DavisVaughan replied here that advising the API to fix the NULL might be one course of action #5189 (comment)

This is previously functional code that now seems to throw an error when an API provides variables that are read as NULL, as I can no longer use bind_rows to move from a list to a data frame. Previous iterations of this code worked fine, so not sure what the change is - as far as I can tell, the API was not altered from previous versions. The last time I know for sure that this code ran without this error was early 2019, and I am only just revisiting it now for a new project.

A quick reproduction of the error:


library(httr)
library(tidyverse)
#reproducible example with a form from Kent Marketing Petroleum Survey
# The code is used recursively build the set of feasible options in a series of drop-down menus from 
 https://charting.kentgroupltd.com/

kent_report_types<-function(product_id=1){
  # for testing, use product_id=1
  #product_id=1
  #For Each Product ID, get a report type
  #Product Report Types
  report_types<-content(POST(
    url = "https://charting.kentgroupltd.com/Charting/GetReportTypes",
      query = list(
      ProductID= product_id
    )
  ))
  
  #what I used to be able to do and would like to be able to do again
  #report_types %>% bind_rows() %>% filter(Value!=0)
  
  #now, that creates this error
#> report_types %>% bind_rows() %>% filter(Value!=0)
#Error: Internal error in `vec_slice_impl()`: Unexpected `NULL`.
# Run `rlang::last_error()` to see where the error occurred.

  # what I have to do now to work around it
  text<-sapply(report_types, function(x) x[[4]])
  value<-sapply(report_types, function(x) x[[5]])
  report_types<-tibble(text,value) %>% filter(value!=0) %>% mutate(product_id=product_id)
  report_types
}

#run the function
kent_report_types(1)

As far as I can tell, the API has not changed from when I wrote the original version of this code using bind_rows, but the API definitely sends a NULL variable:
image

I'd welcome any suggestions of a better work-around or a way to omit the NULL types from the list at reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorvctrs ↗️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions