Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio code VS代码任务中带双反斜杠的路径_Visual Studio Code_Vscode Tasks - Fatal编程技术网

Visual studio code VS代码任务中带双反斜杠的路径

Visual studio code VS代码任务中带双反斜杠的路径,visual-studio-code,vscode-tasks,Visual Studio Code,Vscode Tasks,我想创建一个VS代码任务,它执行一个R命令来将降价转换成PDF。我当前的任务如下所示: { "label": "rmarkdown -> pdf", "type": "process", "command": "Rscript", "args": ["-e", "\"rmarkdown::render('${file}', 'pdf_document')\""], "windows": true, "presentation": {

我想创建一个VS代码任务,它执行一个R命令来将降价转换成PDF。我当前的任务如下所示:

{
    "label": "rmarkdown -> pdf",
    "type": "process",
    "command": "Rscript",
    "args": ["-e", "\"rmarkdown::render('${file}', 'pdf_document')\""],
    "windows": true,
    "presentation": {
        "reveal": "always",
        "panel": "new"
    }
}
问题是,
${file}
返回如下路径:

{
    "label": "rmarkdown -> pdf",
    "type": "process",
    "command": "Rscript",
    "args": ["-e", "\"rmarkdown::render('${file}', 'pdf_document')\""],
    "windows": true,
    "presentation": {
        "reveal": "always",
        "panel": "new"
    }
}
d:\data\documents\myFile.md

但是R需要一个带有转义反斜杠的路径,如下所示:

{
    "label": "rmarkdown -> pdf",
    "type": "process",
    "command": "Rscript",
    "args": ["-e", "\"rmarkdown::render('${file}', 'pdf_document')\""],
    "windows": true,
    "presentation": {
        "reveal": "always",
        "panel": "new"
    }
}
d:\\data\\documents\\myFile.md

如何从
${file}
获取转义路径


使用普通斜杠的替代路径也可以完成此任务,因为R将自动将
/
替换为
\\

VSCode用于返回带有特定于平台的分隔符的路径

作为一种典型的解决方法,您可以创建一个中间脚本,该脚本将条件化从任务传递到它的参数,然后调用您的工具


vscode问题跟踪:中的相关讨论。

感谢您的回答Killy.MXI。当然你是对的,这是一个解决办法。但我不想为此创建一个脚本,我认为解决这个问题的最好方法是提交一个建议,为VSCode开发团队准备接受的路径变量指定分隔符。到目前为止,我只看到提到了替换语法,丑陋到可以被拒绝。我认为完全在任务参数中编写中间脚本是可能的,但是逃避两层脚本将是一件痛苦的事情。单独的脚本更易于维护。是的,我认为您可以在参数中编写脚本。但是我不同意你关于替换的意见。我对VS代码一无所知。但我认为VS代码只在执行期间替换${file}。那么,为什么需要进一步的替换功能来实现自定义替换呢。