2

I am trying to add rows to a data frame if it exists, or assign it to initial data frame in case it doesn't exists. I have tried exists(), missing(), etc, but nothing is working for me.

exists(data) && is.data.frame(get(data))

Error in exists(data) : object 'data' not found

Any help would be highly appreciated. I am trying to do something like

if(exists(data))
    data <- rbind(data,new_data)
  else
    data <- new_data
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
V Gupta
  • 23
  • 1
  • 1
  • 6

1 Answers1

13

If you read the documentation you’ll see that it says that exists requires

a variable name (given as a character string).

In other words, write:

exists('data') && is.data.frame(get('data'))
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214