0

I'm launching from Windows command line (cmd.exe) the following:

C:\Users\lisa>"C:\Program Files\R\R-3.4.0\bin\Rscript.exe" -e rmarkdown::render('O:/ope/Auto/bin/IHYG.Rmd') "https://www.ishares.com/it/investitore-privato/it/site-entry-new?siteEntryAction=ACCEPT&targetUrl=%2Fit%2Finvestitore-privato%2Fit%2Fprodotti%2F251843%2Fishares-euro-high-yield-corporate-bond-ucits-etf%2F1488627371220.ajax%3FsiteEntryPassthrough%3Dtrue%26fileType%3Dcsv%26fileName%3DIHYG_holdings%26dataType%3Dfund%26locale%3Dit_IT%26userType%3Dindividual" "IBOXXMJA Index" "EUR003M Index" "O:/ope/Auto/data/IHYG.csv"

I've also tried the following:

C:\Users\lisa>"C:\Program Files\R\R-3.4.0\bin\Rscript.exe" -e rmarkdown::render('O:/ope/Auto/bin/IHYG.Rmd') --args arg1="https://www.ishares.com/it/investitore-privato/it/site-entry-new?siteEntryAction=ACCEPT&targetUrl=%2Fit%2Finvestitore-privato%2Fit%2Fprodotti%2F251843%2Fishares-euro-high-yield-corporate-bond-ucits-etf%2F1488627371220.ajax%3FsiteEntryPassthrough%3Dtrue%26fileType%3Dcsv%26fileName%3DIHYG_holdings%26dataType%3Dfund%26locale%3Dit_IT%26userType%3Dindividual" arg2="IBOXXMJA Index" arg3="EUR003M Index" arg4="O:/ope/Auto/data/IHYG.csv"

Because I know that the first argument is horribly long, let me split the command line so you can better see each argument:

arg1="https://www.ishares.com/it/investitore-privato/it/site-entry-new?siteEntryAction=ACCEPT&targetUrl=%2Fit%2Finvestitore-privato%2Fit%2Fprodotti%2F251843%2Fishares-euro-high-yield-corporate-bond-ucits-etf%2F1488627371220.ajax%3FsiteEntryPassthrough%3Dtrue%26fileType%3Dcsv%26fileName%3DIHYG_holdings%26dataType%3Dfund%26locale%3Dit_IT%26userType%3Dindividual"
arg2="IBOXXMJA Index"
arg3="EUR003M Index"
arg4="O:/ope/Auto/data/IHYG.csv"

In my R Markdown code chunks, I've set some sink and write to log files to keep a trace of what happens: I write the elements belonging to the args array that comes from args = commandArgs(trailingOnly = TRUE).

Here's what I get:

args[1]=https://www.ishares.com/it/investitore-privato/it/site-entry-new?siteEntryAction=ACCEPT
args[2]=NA
args[3]=NA
args[4]=NA

The hyperlink is truncated and I don't understand why, while the other arguments are completely missing.

Any idea?

Lisa Ann
  • 3,345
  • 6
  • 31
  • 42
  • 1
    What if you escape the & in your url? – Dason Oct 02 '17 at 13:02
  • If I skip it by replacing it with any other character it works, it then wrongly takes spaces as separators between arguments (e.g. `IBOXXMJA Index` becomes `IBOXXMJA` and `Index`). I cannot understand why this happens. Maybe I should replace question's title with _How to manage special symbols in R command line arguments_... So the only thing I can do is to replace `&` **inside** my code chunk? – Lisa Ann Oct 02 '17 at 13:14
  • Does replacing `&` with `\&` fix it? I don't use the windows command prompt so I'm not sure what the proper way to do things is but that did seem to be what was 'breaking' the input. – Dason Oct 02 '17 at 13:34

0 Answers0