问题描述
来自 this 的示例小插图的简单更改网站 说明了我的问题.
A simple change in the example vignette from this site illustrates my problem.
下面的代码将运行.没问题.因为网址中没有空格.
The code below will run. No problem. Because there is no whitespace in the url.
#miniCRAN example
library("miniCRAN")
# use Revolution Analytics CRAN mirror
revolution <- c(CRAN = "http://cran.microsoft.com")
# Specify list of packages to download
pkgs <- c("foreach")
pkgList <- pkgDep(pkgs, repos = revolution, type = "source", suggests = FALSE)
pkgList
# Create temporary folder for miniCRAN
dir.create(pth <- file.path("C:", "RTEMP", "miniCRAN"), recursive=TRUE)
# Make repo for source and win.binary
makeRepo(pkgList, path = pth, repos = revolution, type = c("source", "win.binary"))
# List all files in miniCRAN
list.files(pth, recursive = TRUE, full.names = FALSE)
#install packages from your local repository
install.packages(pkgs, repos = paste0("file:///", pth), type = "source")
但是如果我们更改以下行使其具有空格字符,那么它会在 install.packages 上失败.
But if we change the following line so it has a space character, then it will fail on install.packages.
# Create temporary folder for miniCRAN
dir.create(pth <- file.path("C:", "WHITE SPACE", "miniCRAN"), recursive=TRUE)
在我看来,第 p 个字符串被拆分了.除了更改文件系统中的文件夹名称之外,还有什么办法可以解决这个问题吗?我试图用%20"替换",但这没有帮助.我在 Windows 系统上,顺便说一句.
Looks to me like the pth string gets split up. Is there any way around this, other than changing folder names in my filesystem? I tried to replace " " with "%20" but that did not help. I am on a Windows system, btw.
Warning: invalid package 'C:/WHITE'
Warning: invalid package 'SPACE/miniCRAN/src/contrib/foreach_1.4.4.tar.gz'
Error: ERROR: no packages specified
推荐答案
首先,我认为 file.path("C:", "WHITE SPACE", "miniCRAN")
不是有效路径,因为 C:
后面没有斜线.
Firstly, I think file.path("C:", "WHITE SPACE", "miniCRAN")
is not valid path, because there's no slash after C:
.
无论如何,要将install.packages
与包含空格的路径一起使用,请使用shortPathName
:
Anyway, to use install.packages
with a path containing white spaces, use shortPathName
:
shortPathName(file.path("C:/", "WHITE SPACE", "miniCRAN"))
这篇关于install.packages 不处理文件路径中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!