5

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.

4

1 回答 1

6

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.

于 2017-05-27T10:43:30.977 回答