Chapter 9 Final indications

9.1 Use Projects

To organize your work, not only in RStudio, but also on hard drive you should use projects. It is extremely easy in this IDE. Just click button – Create new project – choose New Directory and type of project you need. RStudio will take care of everything for you. Later you can easily add files of sub-folders with specifying content into your project and use relational links. Also, using projects makes easy to maintain clean global environment, which beginners often tend to underestimate and than they run into troubles.

9.2 Use RMarkdown

To make your work more reproducible, and also to make nice looking output (in html or PDFs) it is a good idea to work in RMarkdown files instead of RScripts. The syntax of RMarkdown is nearly identical to original Markdown, but allows you to execute and store RCode. You can find RMarkdown introduction here. There is also nice cheat sheet which contains all commands you will need. As there is strong pressure to make research and science more open and reproducible, it is strongly advised that you work with proper tools to do it like RMarkdown or Project Jupyter. If you want to learn more, there is very nice guide by British Ecological Society you should read.

Also, you need to know that to make output in PDFs format, you will first need to install LaTeX distribution. There are tons of tutorials how to do it on different operating system. The thing is that even you don’t use LaTeX directly, R uses it under the hood to (oversimplifying) to convert RMarkdown to PDFs. For Linux users, one piece of advice is to install full distribution instead of base, it take more time and disk space, but will save you frustration of installing additional packages later.

9.3 Use .rds files

Usually we work with plain text files like csv or tsv in R. However, there is also a highly valuable format of files called rds, that makes work even more pleasant. It not only preserves all classes of variables, but also takes less space than plain text file, due to compression algorithms. Also when using saveRDS() you don’t need to define hundreds of parameters, just name of object you want to save and its file name. The downside is that it is format to use directly with R and won’t work with other programs.

9.4 Nice resources you SHOULD read

There is few hundred of books relating more or less to work in R. There is also a huge number of blogs, web pages and other on-line resources that helps with work in R. Here you will find some of them that I find very useful in everyday work with R and statistics.





9.5 Solving problems

As you saw, R can be used for many different purposes, like statistics or modeling, whiteout any programming knowledge. However, the more you will work with it, the sooner you will find how programming skills, can help you will daily work. Of course some problems in the beginning will be to complicated to solve quickly, but spending time on finding solution will save you lots of time in future. Also, if you follow few simple rules, you will work faster and be less frustrated. This rules make simple workflow:

  • take some time to analyze the problem
  • divide your problem into small pieces
  • start with solving piece that you know (or are very close to) solve with least effort
  • don’t be afraid to ask or look into web for solutions
  • take all the small pieces and put them together

Remember – it is better to do something than do nothing. Even if you are stuck with something, you will still benefit from solutions for smaller pieces of your problem, that you managed to find. In the beginning try to think about robustness and speed of your code, but do not seek for best optimized code at all cost. Sometimes it’s just not worth spending half an hour to make your code faster by 1 second. The more you will read, the more ideas about how to write best code you will get.