To prepare simple R script and to start playing with R packages, simple Dockerfile was prepared:

FROM centos:7
RUN yum install -y epel-release && yum install -y R
# ADD https://github.com/sassoftware/R-swat/releases/download/v1.6.3/R-swat-1.6.3+vb21030-linux-64.tar.gz /usr/local/lib/
# ADD https://cran.r-project.org/src/contrib/dplyr_1.0.7.tar.gz /usr/local/lib/
# ADD https://cran.r-project.org/src/contrib/jsonlite_1.7.2.tar.gz /usr/local/lib/
# ADD https://cran.r-project.org/src/contrib/httr_1.4.2.tar.gz /usr/local/lib/
COPY script.R /usr/local/src/script.R
# RUN R CMD INSTALL /usr/local/lib/dplyr_1.0.7.tar.gz
# RUN R CMD INSTALL /usr/local/lib/jsonlite_1.7.2.tar.gz
# RUN R CMD INSTALL /usr/local/lib/httr_1.4.2.tar.gz
# RUN R CMD INSTALL /usr/local/lib/R-swat-1.6.3+vb21030-linux-64.tar.gz
CMD ["R", "-f", "/usr/local/src/script.R"]

Some parts with ADD and RUN were comented, because while installing packages directly from CRAN, there are many dependencies, which are not automatically downloaded. To install packages diffent approach was used - by doing it directly from script.R:

install.packages('dplyr',repos = "https://cran.r-project.org")
install.packages('httr',repos = "https://cran.r-project.org")
install.packages('jsonlite',repos = "https://cran.r-project.org")
install.packages('https://github.com/sassoftware/R-swat/releases/download/v1.6.3/R-swat-1.6.3+vb21030-linux-64.tar.gz', repos=NULL, type='file')
                   
print("Test script in R")s

After preparing Dockerfile and script.R, Docker image can be built using commands:

docker build --rm -t centos-r-image .

To start container with shell following command can be used:

docker run --name centos-r-container --rm -it centos-r-image bash

To directly run script following command can be used:

docker run --name centos-r-container --rm -it centos-r-image