I am a new user of blogdown using Hugo. I would like to create a new post that includes R code to read a data file.
The data file is in my static folder, local path C:\mydir\myblogdown\static\data\savedrecs.txt
. Since I was successful in referring to an image using a relative path like this, ![](/images\myimage.jpg)
, I tried reading the data using something similar for the data file, read.csv("/data\savedrecs.txt")
, but that didn't work.
I started playing around with the list.files()
function to see if I could find a relative path that worked in my local version of the post, list.files("../../static/data")
worked, showing me ## [1] "savedrecs.txt"
.
I tried searching around other folks' blogdown repos on Github to see how they might have referred to a data file, but the only example I found referred to a data file using a URL.
You can click in the upper left menu File > Import Dataset > From Excel and select the file to import it. Then you can copy the code that appears in the R console with the code required for import the data in xlsx and then copy it in a R Markdown code chunk.
Go to the Files tab in RStudio (lower right). Click Upload and browse to select the file you created. Then, use the read. csv() function to read in the file.
I suspect that this may be due to the location of your data file. In my working example, the Rmd form of my blog post is in the directory, called p0bs/content/post
. I also add my data file (a CSV in my case) to this directory.
I then treat the rest of the post as I would in a standard Rmarkdown website, with Rmd chunks (that are named without spaces). In your case, that code would include:
read.csv("savedrecs.txt")
I hope that helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With