私信  •  关注

duckmayr

duckmayr 最近创建的主题
duckmayr 最近回复了
7 年前
回复了 duckmayr 创建的主题 » 从Github安装r packge-“”在当前工作目录中不存在

问题在于 R/utils.R ,您尝试从中读取文件 inst/extdata 不存在(来自第36行和第37行):

INPUT.DEFS  <- readr::read_delim(system.file("extdata", "input_defs.txt",  package = "hisafer"), "\t", col_types = readr::cols())
OUTPUT.DEFS <- dplyr::arrange(readr::read_delim(system.file("extdata", "output_defs.txt", package = "hisafer"), "\t", col_types = readr::cols()), profile, name)

检查 内部/外部数据 也不会给你看 input_defs.txt 也不 output_defs.txt 有。

我怎么知道的?

我跑

devtools::load_all("hisafer/")

也会产生错误

错误:当前工作目录中不存在“”。

但允许您显示信息性的回溯:

13.stop("'", path, "' does not exist", if (!is_absolute_path(path)) paste0(" in current working directory ('", 
    getwd(), "')"), ".", call. = FALSE) 
12.check_path(path) 
11.standardise_path(file) 
10.read_delimited(file, tokenizer, col_names = col_names, col_types = col_types, 
    locale = locale, skip = skip, comment = comment, n_max = n_max, 
    guess_max = guess_max, progress = progress) 
9.readr::read_delim(system.file("extdata", "input_defs.txt", package = "hisafer"), 
    "\t", col_types = readr::cols()) at utils.R#36
8.eval(exprs[i], envir) 
7.eval(exprs[i], envir) 
6.source_one(file, envir = envir) 
5.source_many(paths, env) 
4.force(code) 
3.withr_with_dir(file.path(pkg$path), source_many(paths, env)) 
2.load_code(pkg) 
1.devtools::load_all("hisafer/") 

注意回溯中的9号,它不仅显示了有问题的代码,而且还帮助显示了它来自哪个文件以及在哪个行上。

问题的根源:你的 .gitignore

在你 吉蒂格诺 你有台词

inst/extdata/
inst/extdata/*

这意味着中的所有文件和子文件夹 inst/extdata/ 不会被跟踪,因此当用户尝试从GitHub安装时,他们不会获得 extdata/ 它们需要的文件才能使您的包正常工作。

作为旁注,即使用户下载您的回购并手动添加 输入输出 输出命令 ,由于同样的原因,它们没有您希望它们拥有的其他模板目录,因此构建vignette会导致安装错误。

7 年前
回复了 duckmayr 创建的主题 » 使用git2r签出提交时出现问题

有几种方法可以解决这个问题。首先,我将演示如何创建示例存储库,这样您就可以准确地复制:

library(git2r)
path <- "SOanswer"
dir.create(path)
repo <- init(path)
writeLines("Commit1", con = file.path(path, "commit1.txt"))
add(repo, "commit1.txt")
commit(repo, "First commit message")
repository_head(repo)
commits(repo)
writeLines("Commit2", con = file.path(path, "commit2.txt"))
add(repo, "commit2.txt")
commit(repo, "Second commit message")

现在你的问题是如果你跑步 checkout(commits(repo)[[2]]) ,您将丢失提交2,它将不再出现在 commits() . 但是,您只需执行 git checkout master (有关在简单的git上下文中讨论类似问题,请参见,例如, this question ):

list.files(path)
# [1] "commit1.txt" "commit2.txt"
checkout(commits(repo)[[2]])
list.files(path)
# [1] "commit1.txt"
checkout(repo, branch = "master")
list.files(path)
# [1] "commit1.txt" "commit2.txt"

这会把你带到总支的头上。但是,假设您想进行特定的提交。你可以用commit-sha来实现。下面是一个例子:

writeLines("Commit3", con = file.path(path, "commit3.txt"))
add(repo, "commit3.txt")
commit(repo, "Third commit message")
completed_commits <- commits(repo) # Store the commits so we know the SHAs
list.files(path)
# [1] "commit1.txt" "commit2.txt" "commit3.txt"
checkout(completed_commits[[3]])
list.files(path)
# [1] "commit1.txt"
checkout(completed_commits[[2]])
list.files(path)
# [1] "commit1.txt" "commit2.txt"
checkout(completed_commits[[1]])
list.files(path)
# [1] "commit1.txt" "commit2.txt" "commit3.txt"