I have tried to use the workarounds mentioned in other posts (Insert images using knitr::include_graphics in a for loop and Looping through images in directory: ioslides), but I cannot seem to get my code to loop through my images and print them one at a time to separate word docs. (i.e., I have multiple .jpg images saved in a folder and I would like to include each one in a separate word doc.)
Here is my code:
files <- list.files(path = "path/to/myComputer/images/",
pattern = ".jpg",
all.files = TRUE,
full.names = TRUE)
for (i in 1:length(files)) {
cat(', '){width="10%"}\n\n', sep = '')
}
I have also tried:
files <- list.files(path = "path/to/myComputer/images/",
pattern = ".jpg",
all.files = TRUE,
full.names = TRUE)
for (i in 1:length(files)) {
print(knitr::include_graphics(files[i]))
}
I can get it to print all the images on to each separate word doc but I cannot get it to print each image in my folder one at a time. I have read different documentation by Yihui Xie and found it helpful, but I believe I am missing something.
I have separate code that I am using to render each word doc, this code is just to include the images. Any help is appreciated!