How do I include external figures using relative paths?
I start my rmd file with:
```{r setup,include=F}
knitr::opts_chunk$set(cache=F,echo=F)
knitr::opts_knit$set(root.dir = '/Users/dosc3612/odrive/CUDrive/real-time_interpolation',
child.path='/Users/dosc3612/odrive/CUDrive/real-time_interpolation')
```
and then include:
# Heading 1
some text referring to figure 1. ![Figure 1. a map from qgis](data/gis/fig1alt-location_map2.png)
my rmd file is in /Users/dosc3612/odrive/CUDrive/real-time_interpolation/reports/real-time so my understanding is it will look for figures out of that directory. But based on chunk options help I thought I could use child.path to set relative paths in the document but that does not appear to be the case.
"data/gis" is a subfolder in "/Users/dosc3612/odrive/CUDrive/real-time_interpolation"
thanks
Not sure if the question is still relevant for anyone, but I just had a similar problem and couldn't get any of the options of setting paths (root.dir, child.path etc.) to work, but for setting relative paths, this worked for me:
![Figure 1. a map from qgis](../../data/gis/fig1alt-location_map2.png)
The meaning of ../ is the directory one level above the current location, i.e. ../../ means to go from the current level (in this case /Users/dosc3612/odrive/CUDrive/real-time_interpolation/reports/real-time) two directory levels above (in this case /Users/dosc3612/odrive/CUDrive/real-time_interpolation), where in this case you would find the folder "data" with subfolder "gis" containing the figure
Related
My problem is with use of relative links and "compiling" (knitting).
I'm writing a book using RMarkdown. Since the file will be relatively large, I need to split into subfiles and directories.
I have a masterfile which only includes links to chapters(chap1, chap2, ...). There is a file for each chapter and each needs references to some figures (fig1,...).
I would like to be able to knit masterfile.Rmd and chap1.Rmd independently from each others so to get one file for chapters, and one file for the whole book.
Here is how my files are organized (MVE). Directories are displayed in upper case.
ROOT
masterfile.Rmd
FIGURES
fig1.pdf
fig2.pdf
CHAPTERS
chap1.Rmd
chap2.Rmd
...
The code of masterfile.Rmd is as follows:
{r child = '/chapters/chap1.Rmd'}
The code of chap1.Rmd is as follows:
![](../figures/fig1.pdf)
As I knit from chap1.Rmd, everything is fine. As I knit from masterfile, I get the following message:
[WARNING] Could not fetch resource '../figures/fig1.pdf': PandocResourceNotFound "../figures/fig1.pdf"
It seems that fig1.pdf cannot be found. I guess that this is because the include statement in master file only "copies" the code of chap1.Rmd and "executes" it in the ROOT directory (not in the CHAPTERS directory) so ".." drives to location that does not exist (before ROOT) when knitted from masterfile.
I could change the setting and write ![](/figures/fig1.pdf) in chap1.Rmd file. It would work fine when knitting from masterfile but no longer from chap1.Rmd.
Do you know how to have both?
Welcome to the RMarkdown community!
Due to KnitR, Rmd, and pandoc inter-workings, this is not as easy of a solution as you'd think, but a directory restructure would almost be easier.
Even if you look at Rmarkdown author's newest book RMarkdown CookbookHERE. They have all the chapters in the ROOT directory, and only sub directories for images(and possibly figures).
resources:
1. Other SO similar question
2. Github options knitr question
3. similar question from Rstudio community
You can make use of the Lua filter feature to rewrite image paths when knitting the main file. E.g.
function Image (img)
img.src = img.src:gsub('^%.%./', './')
return img
end
This will replace a path like ../figures/fig1.pdf with ./figures/fig1.pdf.
Use the code writing it to a file and calling adding it via pandoc_args (in the main file only).
---
output:
html_document:
pandoc_args: ["--lua-filter=filter.lua"]
---
I would like to compress the folder having the following structure using 7zip or.. using any other zip archive utility available for windows that can use the command line argument in windows and achieve what I want to accomplish.. Here is my folder structure:
/images
/cache
/skin/common/images
/skin/skin1/images
/extensions/extension1/images
What I want to do is, I just want to exclude the top level "images" and "cache" folders from the root folder (The very first two entries in my listing above).
I have tried using the xr!images or xr!/images but.. xr!images removes all images folder. xr!/images just doesn't work.
Can someone please point me to the right direction?
Thanks
Use -x!images instead of -xr!images.
I'm trying to configure the LucidWorks web data source to only index certain file types. However, when I set Include paths to .*\.html to only crawl .html files (as a simplified example), it only ends up indexing the top level folder. Crawl depth is set to -1 and when I leave Include paths blank, it crawls the whole sub-tree as expected.
I've looked at their documentation for creating a web data source, and for Using Regular Expressions, and can't find a reason why .*\.html would not work, since .* should match any character.
As I was proofreading the question, I had an idea which was the correct solution. Posting it here for posterity.
The content being crawled is a file share, so it relies on directory listing of the web server, which was filtered out because it doesn't have a .html extension. So simply adding .*/ to the Include paths fixed the problem.
I've followed the format at http://www.internetofficer.com/awstats/by-directory/ to setup an Extra Section with hits by directory. This works.
images 28273657 38871644 1389.77 GB
content 12607984 12652114 390.53 GB
etc.
However, I need hits by (first level) subdirectory. At the bottom of that page, it suggests using:
ExtraSectionFirstColumnValues1="URL,^\/([^\/]*\/[^\/]*)\/"
Still only shows top-level directories. I've also tried
ExtraSectionFirstColumnValues1="URL,^\/*\/*\/"
which results in the same thing. I can't get the right regexp to do what I need.
Full code:
#Include hits by top 25 directories
ExtraSectionName1="Hits by Directory"
ExtraSectionCodeFilter1="200 304"
ExtraSectionCondition1="URL,^.*$"
ExtraSectionFirstColumnTitle1="Directory"
ExtraSectionFirstColumnValues1="URL,^\/*\/*\/"
ExtraSectionFirstColumnFormat1="<A HREF='/%s/' TARGET='_blank'>%.80s</A>"
ExtraSectionStatTypes1=PHB
ExtraSectionAddSumRow1=1
MaxNbOfExtra1=25
MinHitExtra1=1
You should use:
ExtraSectionFirstColumnValues1="URL,^\/([^\/]*)\/"
I am familiar with theming and using template hints in the Magento back office to locate .phtml files.
What I am not really familiar with are the core files such as app/code/core/Mage/Catalog/Model
What I need to do is override a core file like I would a core phtml file by copying it to 'my theme'.
I basically want to amend some labels which appear on the order summary page of the Magento checkout process - domain.com/checkout/cart/
I followed the trail to the phtml files using template hints. Within the app/design/frontend/default/mytheme/template/checkout/cart I found the code
renderTotals(); ?>
Now I managed, by accident, to stumble upon two of the files I wanted to change:
/httpdocs/app/code/local/Mage/Sales/Model/Quote/Address/Total/Grand.php
/httpdocs/app/code/local/Mage/Sales/Model/Quote/Address/Total/Shipping.php
I made local copies of these files (http://www.magentocommerce.com/wiki/how_to/how_to_create_a_local_copy_of_app_code_core_mage) to override the default labels, like I would if I was overriding a template file.
My question is, how can you locate core files which pertain to the 'stuff' you want to change, located in function calls such as renderTotals(); ?> in the phtml files?
Not being able to pinpoint stuff like I can with template hints is slowing me down, and I am struggling to find a solution as I am not up on all the vocab surrounding Magento yet.
Hope this makes sense and thanks in advance!
From the same settings page where you turn on Template Path Hints, also turn on the "Add Block Names to Hints" setting. This will show you PHP class names such as: Mage_Sales_Model_Quote_Address_Total_Grand to which you can deduce the folder path (underscores represent a subfolder, and the last piece represents the file name).
If you're getting a block such as Mage_Sales_Model_Quote_Address_Total_Default then sometimes it just takes a little common sense to see that it's pulling in other files from the same folder (such as Grand.php and Shipping.php). But there are generally only a couple files in the same folder, so this is pretty easy to see.
As Sid Vel said, a good Search Project functionality is helpful. But if you find yourself looking at Abstract.php of some class, often you need to look in a subfolder in that directory with the proper name to find the concrete implementations. But still, it gets you very close to where you need to be.
I always use Dreamweaver's site / directory search function. It will scan through all the files in the Core folder and tell you where the function is from. In your case, I would search for "renderTotals". You need to enable PHTML editing in Dreamweaver.
Most IDE's will allow this kind of search option. In Aptana you can Ctrl + Click on the function to open the file it is coming from. Magento takes ages to index itself on Aptana, due to its sheer size.