Reading blog data files
I am a new blog user using Hugo. I would like to create a new post that includes R code to read a data file.
The data file is located in my static folder, local path C:\mydir\myblogdown\static\data\savedrecs.txt
. Since I was managing to reference the image using a relative path like this, ![](/images\myimage.jpg)
I tried to read the data using something similar for the datafile read.csv("/data\savedrecs.txt")
, but it didn't work.
I started playing list.files()
around with the function to see if I could find the relative path that worked in my local version of the post, list.files("../../static/data")
worked showing me ## [1] "savedrecs.txt"
.
I tried looking elsewhere for the blogging repositories on Github to see how they could link to the datafile, but the only example I found links to the datafile using a URL.
source to share
I suspect it might have something to do with the location of your data file. In my working example, the Rmd form of my blog post is in a directory called p0bs/content/post
. I also add a data file (CSV in my case) to this directory.
I then process the rest of the post as I do on the standard Rmarkdown website, with Rmd snippets (which are named without spaces). In your case, this code would include:
read.csv("savedrecs.txt")
I hope this helps you.
source to share