@antoine_fabri Let’s take a look at it by using our make_sum function from yesterday. We wrote this simple function that calculates the sum:
@antoine_fabri But what happens under the hood? We can see it here in code language but wouldn't it be great to see it more visually? Here's {flow}'s moment to shine! ✨ Run this line of code and you'll get a flow diagram that shows you how the function works 🥳
@antoine_fabri This looks relatively simple, right? Well, that's the case because it IS a simple function - but it becomes more and more complex, the larger the function gets and the more sub-functions it has.
@antoine_fabri Just try it out yourself with one of your favorite functions 👩💻
And, if you want, share a screenshot of your nested flow diagrams with the #debuggingflow and #rladies hashtags 🥳
• • •
Missing some Tweet in this thread? You can try to
force a refresh
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)
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.