我正在尝试编写一个函数来将项目推送到github,而不是先在云中创build项目。 目前,您可以使用RStudio中的git命令行使用此问题的信息来完成此操作 。
现在我试图把它包装到一个函数中,我可以使用system
从本地仓库创build云中的仓库。 我正在通过这个在Windows和Linux机器上工作(所以不知道这如何在Mac上工作)。 这是我的代码到目前为止(检测混帐位置):
gitpath <- NULL repo <- "New" user <- "CantPostThat" password <- "blargcats" if (Sys.info()["sysname"] != "Windows") { gitpath <- "git" } else { if (is.null(gitpath)){ test <- c(file.exists("C:\\Program Files (x86)\\Git\\bin\\git.exe"), file.exists("C:\\Program Files\\Git\\bin\\git.exe")) if (sum(test) == 0) { stop("Git not found. Supply path to 'gitpath'") } gitpath <- c("\"C:\\Program Files (x86)\\Git\\bin\\git\"", "\"C:\\Program Files\\Git\\bin\\git\"")[test][1] } }
然后我试着用system
:
system(paste(gitpath, "--version")) > system(paste(gitpath, "--version")) git version 1.7.11.msysgit.1
看起来不错。 但是,我尝试一个真正的代码块:
cmd1 <- paste(gitpath, paste0("curl -u '", user, ":", password, "' https://api.github.com/user/repos -d '{\"name\":\"", repo, "\"}'")) system(cmd1)
并得到消息:
> system(cmd1) git: 'curl' is not a git command. See 'git --help'. Did you mean this? pull Warning message: running command '"C:\Program Files (x86)\Git\bin\git" curl -u ' trinker : PASSWORD ' https://api.github.com/user/repos -d '{"name":" three "}'' had status 1
我怎样才能运行这个命令:
curl -u 'USER:PASS' https://api.github.com/user/repos -d '{"name":"REPO"}'
。
我也尝试运行,而不是先把git放在前面。 我目前正在赢得7台机器
在我看来,它看起来像你试图运行curl作为一个git命令system("git curl")
,这显然是行不通的。 我想你需要在Windows上找到curl二进制文件的安装路径,类似于上面对Git可执行文件所做的操作。 在Mac OS X上,您可以像这样运行您的命令…
system("curl -u \'USER:PASS\' https://api.github.com/user/repos -d \'{\"name\":\"REPO\"}\'")
记住要避免字符串中多余的引号。
我想你甚至可以下载编译后的curl二进制文件并从下载位置运行它? 我没有访问我的Win7框在工作测试这从复制和粘贴运行,但你得到的想法…
url <- "http://curl.askapache.com/download/curl-7.23.1-win64-ssl-sspi.zip" tmp <- tempfile( fileext = ".zip" ) download.file(url,tmp) unzip(tmp) system( paste0( tempdir(),"/curl", " -u \'USER:PASS\' https://api.github.com/user/repos -d \'{\"name\":\"REPO\"}\'") )