Linked Questions

7 votes
1 answer
3k views

Verify object existence inside a function in R [duplicate]

I want to determine whether an object exists inside a function in R: foo <- function() { y <- "hello" if (exists(y, envir = sys.frame())) print(y) } foo() Error in exists(y, envir = sys....
InspectorSands's user avatar
0 votes
0 answers
73 views

Test to see if object exists in R [duplicate]

Is there an easy way to see if an object exists in R? I would love a function that returns TRUE if the object has been defined and FALSE if the object has not been defined. Thus far, everything I try ...
tcarpenter's user avatar
129 votes
7 answers
83k views

Filter for complete cases in data.frame using dplyr (case-wise deletion)

Is it possible to filter a data.frame for complete cases using dplyr? complete.cases with a list of all variables works, of course. But that is a) verbose when there are a lot of variables and b) ...
user2503795's user avatar
  • 4,145
135 votes
7 answers
137k views

How to test if list element exists?

Problem I would like to test if an element of a list exists, here is an example foo <- list(a=1) exists('foo') TRUE #foo does exist exists('foo$a') FALSE #suggests that foo$a does not exist ...
David LeBauer's user avatar
24 votes
1 answer
26k views

R : Check if R object exists before creating it

I am trying to skip steps loading data from large files if this has already been done earlier. Since the data ends up in (for example) mydf, I thought I could do: if( !exists(mydf) ) { #... steps ...
rstruck's user avatar
  • 1,274
9 votes
2 answers
1k views

List of packages that need an update

How can I produce a list of packages that need an update, i.e. a table with package name, version currently installed and version available at the repository? I have tried to hack packageStatus(), ...
Tomas's user avatar
  • 59.4k
-1 votes
2 answers
9k views

R - check if a variable exists

I thought I had figured this one out. I have a variable called: count_1 It's just a vector with one element. As I go through my loops, sometimes it has a value, and at other times it doesn't. All I ...
Gotmadstacks's user avatar
1 vote
2 answers
496 views

How to check if any variable is defined in argument (...) in R?

If I have a function with argument (...) and want to check if a variable is defined in the argument. How can I do this? I have already looked at the solution provided at this link: How to check if ...
Rahi's user avatar
  • 175
1 vote
1 answer
1k views

If value exists in environment

Is there a way how to check if value exists in R environment and if == TRUE, assign this existing value otherwise assign something else? In other words, I have nothing in my R right now and I created ...
user avatar
0 votes
2 answers
404 views

How to check if an executable command exists in R

Is there a way in R to check if a command exists in the operating system? I know that file.exists(file) can be used to check if a file exists. But what about a command on the system PATH? (This is ...
thor's user avatar
  • 22.4k
-2 votes
1 answer
170 views

detect numeric values in a string

I have to create a function which will detect if there is any non numeric value present in input. For this I have written this code test<-function(x){ if(is.numeric(x)){ return(T) }else{ ...
Rajarshi Bhadra's user avatar