To use this package you need to work in RStudio. The goal of
qpost is to create and open a Quarto blog post with the
appropriate YAML front matter in RStudio.
qpost() displays a dialog window where you can enter the
data for the YAML header of a new blog post.
Dialog window for creating a blog post
After clicking the “Done” button the function generates the core skeleton of a Quarto post. This includes:
index.qmd file with the YAML header
populated from the data of the dialog windowYou can choose from your categories already created or add new
categories. With the package comes also an RStudio Addin so you can bind
the qpost() command with a shortcut.
You can install the package from CRAN with:
install.packages("qpost")Or install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("petzi53/qpost")library(qpost)
if (interactive()) {
qpost()
}To create Quarto posts even easier, you can configure
qpost:
If you are the only blog author on your machine, you can add your name to the author field automatically.
.Rprofile. The easiest way it to install
usethis` and open .Rprofile with
usethis::edit_r_profile()..Rprofileoptions(qpost.author = "<your name>")
If you want to prevent the confirmation question before
qpost() creates the folder with the post, the YAML header
and (optionally) copies your chosen image, add another line into
.Rprofile:
options(qpost.verbose = FALSE)
You can specify if you want the new post with
draft: true (Standard) or draft: false.
Not all fields are always needed. The default is to get the full list
of all YAML fields provided by the dialog window, even if some of the
fields are empty (show_empty_fields = true). With
show_empty_fields = false only those fields with contents
are displayed in the YAML front matter.
If you are going to add all lines to .RProfile, then
your code snippets should look like:
options(
qpost.author = "Peter Baumgartner", # default = ""
qpost.verbose = FALSE, # default = TRUE
qpost.draft = FALSE, # default = TRUE
qpost.show_empty_fields = FALSE # default = TRUE
)
Do not forget to restart RStudio after you changed
.Rprofile!
I am not very experienced in R programming, so I am very grateful that I could take help and suggestions from different sources:
I started with qpost() after a question or feature
request at the Posit
forum. I got some helpful links that I tried out and used as
precursors for my implementation.
I took the new_post()
script from The Mockup blog as an advanced organizer for the general
structure of my approach. It has a very extensive and understandable
explanation. I learned about the kebab notation I had never heard about
until this blog post. For German umlauts – and special characters in
other languages -, I added the line
stringi::stri_trans_general((title), "latin-ascii")
(learned from a StackOverflow
answer).
I also used some ideas from the newpost package, particularly the use of RStudio Addins and the request that users choose from categories already used.
My knowledge of R programming is limited, but I am a complete newbie when it comes to Shiny apps. (I just started reading the fantastic Mastering Shiny book by Hadley Wickham.) I took the general structure of the Shiny window from the blogdown “New Post” RStudio addin by Yihui Xie. The lack of a similar function for Quarto was generally my main incentive to start with the qpost project in the first place.
I tried to follow the advises of R Packages in preparing this package for CRAN.
I am sure that my code is not efficient and that there are many ways to improve my package. I am very interested to learn better programming in R / Shiny / (JavaScript). If you find bugs or more efficient ways to solve my intended goal please do not hesitate to raise an issue or provide a pull request.