2020/9/21

R Programming Language - Run R Script

To run R script, install RStudio.

Add a new R script file and save it as a *.R file.


The code in the new script file can be:

a = 1

b = 2

a+b

When executing the script file, move the cursor to the first line of the script.

Press the run button, one line is run and the cursor is moved to the next line.

In the above example, press the run button three time for the three lines as below:



Related Information:

Installation and basic R commands

R programming language - load and save data

2020/9/3

R programming language - load and save data

This article explains the commands to load and save R data.

Firstly, declare data x:

    x = c(1,2,3,4,5,6)

Get the local path: getwd()

    path = getwd()

Change path:

    pathnew = file.path(path,"Desktop")

Set the local path: setwd()

    setwd(pathnew)

Save

    filename = file.path(pathnew,"test.RData")

    save(x,file=filename)

Clear workplace

    rm(list=ls())

Load

    filename = file.path(getwd(),"test.RData")

    load(filename)

    > x

    [1] 1 2 3 4 5 6

Related Information:

How to save and run an R Script

Installation and basic R commands