Error with NULL values in a data frame R

Asked

Viewed 75 times

1

Hello,

I am working on building a data frame in R from a JSON that I receive after doing a GET on a service, but I am getting an error because one of the return JSON values is null, it follows part of the code used:

    id <- callback$data$id
    uri <- callback$data$uri
    name <- callback$data$name
    email <- callback$data$email
    status <- callback$data$status

data <- data.frame(id,
                   uri,
                   name,
                   email,
                   status) 


  data <- tibble::as_tibble(data)

Follow JSON of return:

  “data”: {
    "id": 7658,
    "uri": "https://sampleuri.io/samples”,
    “name”: “A return example“,
    “email”: null,
    “status”: “ACTIVE”,
   }

Follows error:

Error in data.frame(id, Uri, name, email, status, : Arguments imply differing number of Rows: 1, 0

I tested by removing the email variable and the data frame is created correctly, someone could help me in a way to make R accept the null value of the email variable?

Thanks so much for your help.

  • 1

    Change to NA: maybe sub('null', 'NA', callback$data$email). This is because length(NULL) is equal to 0.

  • Hello @Ruibarradas Thanks so much for the tip, it worked :D

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.