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:

... 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


YouTube channel lists – Python working with files

Have you ever wondered how to work with files and get access to them and look at their contents?

In today’s environment, there is a frequent need to work with files, import do some work on them and then either save them somewhere or pass them onwards for further processing.

Working with files can happen in several ways:

  • You import them from a local or network drive.
  • The files are transmitted electronically to be stored on a destination server and then processed.
  • They could be received via email and need to be extracted and processed.

The videos in this data analytics series will hopefully help to explain the different concepts and ways of working with files; you may need to address or write a programme to address.


We hope you like and please subscribe through the social media buttons on the page if you want to hear more from us!

Data Analytics Ireland