I created and maintain this blog with blogdown in RStudio. Because I use blogdown I can write a webpage with R Markdown language, click a Build button, push the page to Github, and forget about it. Creating a website and posting that site online all happens behind the scenes. The initial steps to create a blogdown site are somewhat convoluted and tedious, but once the site is created the process of actually posting blog articles is a snap, and can be done from within RStudio.
Step 1: Select a Domain Name
While this step is optional, I recommend that you select a domain name for your blog site. If you do not have a domain name then Netlify (where the site will be hosted) will provide one for you, but it will be something like “stupefied-pike-e1c9ad” or “agitated-booth-b760d7”. While there is nothing wrong with names like those, it will be hard for your blog readers to remember.
If you elect to purchase your domain name from Netlify it will simplify your site creation process if you first search for a domain name that you like just to make sure it is available. You can use Name.com to search for a domain and get a feel for how much that domain will cost. You can probably find a domain name that you like for only about $10/year. I’ve found that the Netlify costs are about $2 higher than name.com but that tiny bit of expense will save you a world of setup headaches and, for me, is well worth the expense.
Once you have found your domain name, just keep in in mind for Step 6, when you will link that name to your blog site.
Step 2: Github
Create a free account for yourself at Github. This is the intermediate step in the blog publishing process so it is important. My GitHub home page looks like this.
If you are starting with a new Github page then you won’t have any repositories listed, but if you are reading this blog then you likely already have a github account so this won’t be new to you. If you are creating a new blog site from scratch, then click the large, green New repository button. You will need to name the repository and give it a description. I would recommend that you name your repository the same as the domain name you want to use. There are a few options you should consider:
Public/private. Free accounts have only a “public” option available, but if you are using this repository for your blog site then there is no point in making it “private” since your blog will be public anyway.
Initialize with a README file. While this is probably nice to have, this file will keep you from initializing your blogdown site. You can add a README file to your repository later if you wish, but for now do not initialize with a README file.
Add .gitignore page. You will want to add a .gitignore page and select R in the dropdown box. This will keep files like your R history from being uploaded into Github and those files serve no purpose on Github. Additionally, you may eventually have certain files that you intend to not share with the world (like API keys or JSON files), and you can add those to the .gitignore file so they are not uploaded to Github.
Add a license. While this is probably nice to have, this file will keep you from initializing your blogdown site. You can add a license file to your repository later if you wish, but for now do not add a license.
When the repository has been created, click on its name to open it. In a new repository there should not be many files, just a .gitignore. Look for the green “Clone or download” button on the right side of the repository and click that button.
Click the “copy” button (it looks like a clipboard) to copy the repository URL to memory. This URL will be used in the next step, but for now you are finished with Github; however, leave it open since we will be back.
Step 3: RStudio
Open RStudio on your computer. You will want to create a new project for your blog, so click File -> New Project.
On the next screen, select a “Git” repository. Then paste in the URL that was copied from Github in the previous step and select the location for your blog files on your local computer.
After a few seconds, you will have your Github repository ready to go on your local computer.
Step 4: Create a Blog
In RStudio, install the blogdown library if you have not already done so. Next, start a blogdown project with this command in the RStudio console:
The system will whir and click for a few seconds, but then you’ll have a blogdown site. RStudio will automatically start the internal site viewer and any changes you make to your blog will be instantly reflected in the viewer window.
While there are many options to explore with blogdown, for this tutorial all I care about is creating a minimal site that we can serve. So, let’s push what we’ve done back to Github.
Click the “Git” tab in the top right panel.
This tab shows the files that were deleted (red “D” box), added (green “A” box), and changed (yellow “?” box). To accept these changes and then upload the changed files back to Github, click the “Commit” link.
On the “commit” page, check the box beside each line and then add a commit message. This message should indicate what changes were made to the site and be meaningful in case you ever need to “roll back” a commit at a later date.
Click the “Commit” button and wait until RStudio commits those changes. Then, click the green “push” button in the top right corner of the Git window to push the changes back to Github. Now, close the “Git” window.
At this point, you can log back into your Github account and notice that now the repository has a lot of files and folders that it did not have earlier. This is your blogdown site.
Note: While the above steps work, I’ve found the GitHub process to be slow and cumbersome in RStudio. Therefore, I use the free GitKraken client on my computer. Once I finish with a blog post and rebuild the site, I open GitKraken and use that to commit and push the site to GitHub.
Step 5: Netlify
You need to create an account at netlify to host your blog site. Netlify has a free and and several different paid “team” versions, but all you will need for your blog is the free version.
Once you create your account, click the green “New site from Git” button on your Netlify home page.
On the next screen, select “Github”.
If you have never linked Netlify to Github then you will next go to a screen that requests permission to access your Github account. You will need to authorize this in order to use blogdown with Netlify.
Netlify will go to your Github account and generate a list of your repositories. Select the repository of interest, “gself” in this case. Note: it is fine if the repository is named something different from your selected domain name, but if they are the same it may reduce potential confusion as you work with this system in the future.
The next screen to pop up has several netlify options, but you can leave them all at their default values. If one of these options need to be changed you can do that later.
Click the green “Deploy site” button at the bottom of the page.
It should only take a few seconds to deploy the site, then you will see a success message similar to the following (though your URL will be different).
If you click the URL link you will see your new blog site.
Step 6: Domain Name
To purchase a domain name for your blog site, go back to your main page in netlify and click on the URL that you just created. For this tutorial, I’ll click on “heuristic-spence-1ac73c” since that is the temporary domain the Netlify created for me.
On the URL properties page, click the “domain settings” button.
Click the “Add custom domain” button.
On the next screen, enter the domain name that you want to purchase. For this tutorial, I’ll purchase “georgeself.name”. Then click the “verify” button.
You will need to add a credit card payment method before you can proceed. Once that is done, click the “Register domain now…” button.
After a few seconds, the domain is purchased and you will be able to access your blog by entering that domain in the web browser. Note that the domain must be “propagated” before it is active. Web hosts will tell you that it can take up to 48 hours to propagate a domain name, but I have found that it is usually done in just a few minutes. The point is, though, don’t get excited if you enter your shiny, new domain name in your browser and get a “site not found” error. Give it some time and it will eventually work.
I tried the new domain that I had just purchased immediately after I typed in the last paragraph (a couple of minutes) and the blog popped up, so the propagation took only a couple of minutes!
Step 7: Back to RStudio
Now, your only job is to set up your new blog and start writing blog entries. I recommend reviewing the blogdown documentation. This is a full book that is made available online, but you can purchase a print copy at Amazon for $23.42 softcover or $14.72 Kindle.
Once I finished this blog post and saved the Rmd file, I clicked the “Clean” link in the “Build” tab in RStudio, then I clicked the “Build Website” link. After a few seconds, the site was built, so I uploaded all changes to GitHub then after a few seconds found the new post online.
It takes a bit of effort to get blogdown set up, but once that is done creating a new blog post is as simple as entering some text in an RMarkdown document in R Studio, clicking the “build” button, and pushing it to Github.
I would encourage you to explore the various options for blogdown and then enjoy using this great tool for your own blogs.