basics of R Language

Files operation in R Language

Files operation in R Language

Till now we have seen example by typing the code into command line and it works only for short scripts. So to execute R program later, we can store it in a text file (with extension .R). It can be run directly from the command line or from a running R instance.

Let’s see some of the stored R scripts.

Files operation in R Language

In my system I have two R scripts bottle1.R and bottle2.R.

By using list.files() function we can display the stored R scripts in current working directory.

How to run a script in R

To run a script, pass a string with its name to the source function.

Files operation in R Language

Press enter to run:

Files operation in R Language

Now try to run bottle2.R

Files operation in R Language

These are massage I have stored in both files.

We will learn more about files in upcoming tutorial.

Leave a Reply