R – How to check a file exists and is not empty

Here is another way to check if a file is empty, this time in R!

In the recent past, we posted about How to check if a file is empty in Python, this post looks to build on that and show you in R Programming how to get the same effect.

When looking at the two programming languages, that while the concepts are pretty much the same, the syntax used to achieve the outcome can be slightly different; hence you have to remember which language you are in when writing the code!

Ensure the files exists and open it, gotta be confident it there 🙂

As a preliminary step we check to see if the file exists using:

if(file.exists("emptyfilea.txt")
... rest of your code

 

Then we go and see if the file is empty or not. The full code can be viewed here.

Additional information to help you along the way.

I have referenced this site before, it has some very useful explanations of different functions and methods, for files Check R Documentation

Data Analytics Ireland

 

Leave a Reply

Your email address will not be published. Required fields are marked *