> For the complete documentation index, see [llms.txt](https://r-pedia.gitbook.io/cevi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r-pedia.gitbook.io/cevi/hello-r/r-environment.md).

# -R environment

## #R vs RStudio

#### Term: <a href="#term" id="term"></a>

-Graphical User Interface (GUI)**:** User Interface or a simple term anything that you can see on your computer

-Integrated Development Environment (IDE): A software application to write a computer programm

**Introduction to R:** R is a language and environment for statistical computing and graphics

**The R environment (R-IDE)** has some of features, it includes:

* Input and output , loops function, rekursive
* Create an analytical graph
* Operators in different data object such as matrices, data frame, etc
* Storage facility
* Data handling
* Simple GUI
* Saving graph as pdf

&#x20;**Introduction to R-Studio:** R-Studio is open-source IDE for R and has better GUI to connect with R

## #RStudio User Interface

&#x20;RStudio has 4 layer of GUI

![](https://4050850663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LJ9jSFe6fncOCaGtdZ3%2F-LLa6QaMO-Uzvek5bdba%2F-LLa6aOQLpHRu9jVdPtq%2Frstudio-windows.png?alt=media\&token=e1cf1bfb-468d-467f-8868-9a2eacf7cf76)

## #RStudio support

#### RStudio built in "Help" <a href="#term" id="term"></a>

* ​[Getting Started with R](https://support.rstudio.com/hc/en-us/articles/201141096-Getting-Started-with-R)​
* ​[Getting Help with Rstudio](https://support.rstudio.com/hc/en-us/articles/200552336-Getting-Help-with-R)​

```r
?mean()         # help about function mean()
help(mean)      # another help syntax about function mean()
help.start()    # go to manuals help (built in help system)
example(mean)   # show an example of function mean()
apropos("mean") # show all functions containing at least string "mean()"
```

## #R directories

&#x20;R directories is the current workspace working directory in our computer- or the address of our folder for save the R objects

```r
getwd() #get the current working director
setwd(mydirectory) #setting the directory, use / in windows
```

#### **Or use the RStudio GUI : Session pane->Set Working Directory->Choose Directory** <a href="#term" id="term"></a>

## #R packages

&#x20;Packages are collections of R code. The directory where packages are stored is called the library

#### &#x20;Available Packages: <a href="#available-packages" id="available-packages"></a>

* A complete [list of contributed packages](http://cran.r-project.org/web/packages/) is available from [CRAN](https://cran.r-project.org/)​
* Search for newest packages, functions, authors, etc from [RDocumentation](https://www.rdocumentation.org/) ​

#### &#x20;Setting the library: <a href="#setting-the-library" id="setting-the-library"></a>

```r
library()    # to know all packages 
installed search()     # to see packages currently loaded
.libPaths()  # get library path (location)
```

#### &#x20;Installing additional Packages: <a href="#installing-additional-packages" id="installing-additional-packages"></a>

```r
install.packages("nameofpackages") #install
library(nameofpackages) #or    #using the packages in RStudio
require(nameofpackages)        #same with library()
```

#### &#x20;Creating Your Own Packages: <a href="#creating-your-own-packages" id="creating-your-own-packages"></a>

* ​[Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html) from r-project
* &#x20;[Creating R Packages: A Tutorial](http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf) from F Leisch
* &#x20;[Making R packages Under Windows: A Tutorial](http://www1.appstate.edu/~arnholta/Software/MakingPackagesUnderWindows.pdf) from Rossi's

## #R input/output

#### Input from the current working directory: <a href="#input-from-the-current-working-directory" id="input-from-the-current-working-directory"></a>

```r
# input a file 
source("myfile")
```

#### &#x20;Reusing output results: <a href="#reusing-output-results" id="reusing-output-results"></a>

&#x20;The R output can easily be saved and used as input

```r
x<-200 #save x which has value 
200y<-x+1000 #x as input for yxy
```

## #R extra environment:

-Build interactive web apps straight from R: <https://shiny.rstudio.com/​>

&#x20;-Build interactive document straight from R: <https://rmarkdown.rstudio.com/index.html​>

-The bookdown package is a free and open-source R package built on top of R Markdown to make it really easy to write books and long-form articles/reports.:&#x20;

* &#x20;<https://bookdown.org/>​
* &#x20;For the comprehensive documentation of **bookdown**, please see <https://bookdown.org/yihui/bookdown>.

\- R Markdown thesis template using the bookdown package: <https://github.com/ismayc/thesisdown​>
