๐ฉ๐ผโ๐ป How do you use GitHub and RStudio?
If you connect your local repository with a remote repository (for instance on GitHub), youโll be able to store it also in the cloud and access it from everywhere. Setting up this connection is easy in @rstudio - just follow these steps:
@rstudio You can see one detailed use case in the GIF. It shows how I typically set up a project in #rstats with GitHub when working in academia
@rstudio@AcademicChatter I create a #GitHub repository first (depending on data privacy and other things, I go for either public or private but I always add a README. READMEs are great because they allow you write a short description of your repository in #markdown)
@rstudio@AcademicChatter Then I go back to my RStudio desktop version and select "File" > "New project". To enable version control, select here "Version control" and then copy-paste the link from your GitHub repository ๐
@rstudio@AcademicChatter I realized that I usually start with a similar setup when working on an academic project, so I wrote a few code snippets that populate my #Rproject with files and folders ๐ช
@rstudio@AcademicChatter You can either always copy-paste this code or turn it into a code snippet that lets you run it automatically when typing "academic" (or whatever you word) and hitting "Tab".
@rstudio@AcademicChatter Here's how it works with a header (but it can be transferred to other use cases)
๐
@rstudio@AcademicChatter I tweaked it quite a bit over the years and I'm always trying to improve things - so please share if you have a different approach or other preferred setups that work well for you ๐ค
@rstudio@AcademicChatter ๐ If you want more detailed insight into how to get the most out of a (semi)automatic setup of your workflow (including the code), hereโs a short blog post I wrote about it: bit.ly/r-project-setup
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh
Today's about version control and collaboration today and one of its powerful tools: #git โจ
๐กWhat is Git?
Using Git can be a lifesaver (and it has often been one in the past for me ๐). Itโs basically like a mini time travel machine that you use - it allows you to have version control of your work progress.
But unlike Dropbox or other tools, it does not automatically save the status quo of your work but requires you to do it actively with commits and pushes. A typical workflow looks like this ๐
In the last thread, I described in brief how to set up your #rstats package - but as you have already seen, a package contains a bit more than just your function(s) โจ
When building your R package, you can luckily rely on the work of others who provide an excellent framework to get you started (and also take care of some of the things in the background).
I found it difficult to understand "what" I really need and "why" when I started writing my first package. So here's a short list with what I believe are among the most helpful tools out there:
Now that you know how a general package structure looks like, we can start building a package ๐ฉ๐ผโ๐ป
#RStudio is great, just follow these steps: Select "File", "New Project...", "New Directory" and select "R Package". You can now give your R package a meaningful name, select a path and hit "Create project".
You're now ready to go! Once executed, you have a fully functional package structure in your #Rproject (that we already discussed) ๐ Now it's time to move your function to your "R/" folder and populate it!
Writing a package sounds big -and it can for sure be. But in its simplest form, itโs not that much more than putting a function in a package structure. The #rstats community is great and came up with multiple great helpers that make your life easier!
๐ก Whatโs in an R package?
Simply speaking, an R package allows you to put functions in a box and make them available for others to use.
Ideally, your R package also comes with unit tests that make sure that your package works (or if it doesn't throw meaningful errors and let you dive into the functions and explore why it doesn't) and it adheres to the common standards of developing a package.
Before we get into ๐ฆ development, I wanted to share my favorite shortcuts in the RStudio IDE with you. There are so many out there (bit.ly/rstudio-shortcโฆ) but these are the ones that I regularly use when changing something directly in my code ๐ #rstats
I love them because they usually make your life easier. The first one allows you to add a new R code chunk in your Rmd/Quarto file using "Option + Cmd + I" on a Mac (or "Ctrl + Alt + I"). And this is exactly what the GIF shows:
The next one makes writing a type operator so much simpler! At first, it feels a bit like looking for the keys but once you have it inherited, you probably won't want to go back ๐ So instead of typing "%>%" you can now use "Cmd + Shift + M" on a Mac (or "Ctrl + Shift + M")