Before delving into data and Data structures in R, let’s know, configure and take into account RStudio environment generalities
Working directory configuration
To work calmly on our projects we must always establish an order, this will give us skills to work more effectively.
One simplest and least named steps, it could help us in our projects in RStudio, it’s to configure our directory. Working directory (wd) is a folder (on our computer) that RStudio uses to read or write files. To know address folder (By default), we have to type next function in console
A tip to facilitate your learning: The vast majority of R code syntax is related to function they are going to fulfill. For example,
Attention attention!!!
getwd() is get working directory.
getwd()
## [1] "C:/Users/david/Desktop/Rbiologos/content/english/blog/A004"
So, you can see that my directory path is set to work on a folder in my desktop. But if I need to work in a specific project folder, I can change this address with command
setwd(C:/Users/david/Desktop/Proyecto)
Likewise, if we want to know all files that are in our directory, we can execute
![](https://i.ibb.co/mq00bvC/download.gif)
But wait … we advise you to configure your directory permanently to be able to streamline and organize your projects/data in best way (I have it on desktop folder because it’s where I have everything at hand). In order to do this, in application we are going to go to
So we will see it this screen
![Options](https://i.ibb.co/VQ66vjC/Options.png)
In this panel we will have several options that you can modify such as RStudio appearance, font size, work panels order, among other. In our case, in General option, we will go to
Packages
Configured already our directory, the next step is to know that R is composed for a base system, this means that it has functions already installed to be able to perform simple tasks, however, there are multiple functions and tasks in R world. To be able to extend this functionality, R can install packages that have a functions collection predetermined by their developer.
So, there are several ways to install these packages. The most common and simple is through
install.packages("lme4")
Or, we can install several packages at same time with this code:
install.packages(c("dplyr","ggplot2","lme4"))
One RStudio advantages is that when you load a script (in this same post we will talk about these), the program will automatically read packages not installed and will ask if you want to install them, as we can see in this image
![library](https://i.ibb.co/JKSd65j/library.png)
This installation is necessary only once, this is because package will be incorporated into base information on our computer.
All we have to do is “call” at package. We carry out this task when we have to use any of its functions, the code to execute this command will be
library(lme4)
# Note that we no longer need name to be in quotes
Yes, it’s very possible that you find yourself in a dilemma, and you don’t know how package works, because your teacher told you, to work with this thing you need this package, nothing more. And in this moment the biologist begins to suffer.
![](https://i.ibb.co/xstVGxy/fran.gif)
But don’t worry …! Nothing is lost and R developers have arranged that packages have necessary information to help users in this complex process. To access this help we type in console
And help tab will open and will show information as in next image:
![Help](https://i.ibb.co/G5YcY59/Help.png)
But… all information will not always be so clear, it’s a reality. For this, several people have created pages or blogs dedicated to solving any doubts in R environment. The most sought after and used are these:
![rbloggers](https://i.ibb.co/28tJ17T/rbloggers.webp)
R-bloggers
![stackover](https://i.ibb.co/0ncXRPX/stackover.png)
Stackoverflow
We invite you to explore them, they have very good information, with discussion forums, mostly in English
Functions
With our packages installed we can work! Each packages has a number of functions that have a specific task to perform.
Thus, a function is a operations series to which a name has been assigned, these functions require specific
![](https://i.ibb.co/BnpY7SN/hate.gif)
It is essential to know arguments that we need to enter each function!
To know arguments we can consult packages’ help, as we saw earlier, for example:
![Argumentos](https://i.ibb.co/CnMCVVG/Argumentos.png)
Required arguments view for lm() function
Scripts
To finish our topic, we are going to talk about Scripts, but… What is a script?
A script is an R document whose purpose is to save codes that we create important for a project, it is something like a cooking recipe. Once you have all your codes saved, it’s only necessary to open script to have them at hand and to be able to use or modify them.
To create a new one, you just need to go to
Scripts are recognized because they have an
![script](https://i.ibb.co/H2gZRPV/script.png)
Script editor view in RStudio
To run all codes within script you can click on
One advice, to work with your codes, directly from script editor and NOT in console. But why would it be better? Answer is simple, nothing better than not losing sight of codes that have worked for you, or editing code quickly to correct an error, in console you would have to be writing complete code, and if it is long, well, it becomes tedious.
In RStudio you can save editor contents frequently, and Rstudio will load them automatically when you reopen them.
In summary
Today, First, we were able to learn or remember to identify and configure our work site; We hope that with this step, your work in R will become much easier, we believe that doing things more easily frees us from simple tasks, to be able to concentrate more on what is really worthwhile.
Likewise, we learned about packages use, how to install them and how to use them. Keep in mind that there are currently 17258 packages available for R and that number continues to grow, each with a special functions collection and each function with its specific arguments, so don’t stress about not knowing everything about them. We are learning and we are going step by step, soft, soft, soft!
![](https://i.ibb.co/SB9Syr0/realx.gif)
And finally, we talked about scripts. Important files to be able to save our codes and have them always at hand.
Finally
We invite you to continue investigating more on subject, we also want to know about your experience in R and RStudio and what doubts we can help you solve. Thank you very much for your time, we hope you have learned something new, it is important for us to contribute something to humanity learning!
We wait for you in our next post, which is loaded with many more things. We will tell you everything!
Information R
Vicente Coll & Pedro J. Pérez.Universidad de Valencia;
Andina M. (2018); Ahumada, J. A. (2003);
R para Principiantes. University of Hawaii; Mendoza Vega (2014).