Closed mvuorre closed 4 years ago
Interesting, I'll take a look and see if I can spot anything. Just about to email you re: the manuscript
There are also some hacks in the build process that should be removed (e.g. it uses setwd()
because create_package()
doesn't otherwise know how to get into the newly created directory to add the other components.) There's some RStudio magic involved that I don't currently understand enough to fix it.
It gets even stranger. I just created a new vertical project, closed RStudio, and opened RStudio again. This time there was no problem. I then closed RStudio, deleted the directory of the new project and reopened RStudio. It now opened with the deleted Supplemental_1.Rmd file active, with the message "The file doesn't exist...".
Am trying to reproduce the error this morning. I had RStudio set to load previous project and files, and with those settings, didn't have a problem. I unchecked both settings, then followed your steps and was able to reproduce the error. Reloading Rstudio opened a "none" project, with the supplementary file loaded...very strange, will see if I can track down the issue.
Eliminating some possibilities:
Checked to see if this was purely a usethis::use_article()
problem, doesn't seem to be.
usethis::use_article()
Suggests something about our build process
No problem with vertical::init_vertical_project()
...
vertical::init_vertical_project()
to initialize a vertical projectSupplemental_1.Rmd
to the editor pane.Supplemental_1.Rmd
was not loaded.Suggests something about usethis::use_article()
opening the vignettes in the editor window...almost as if it tries to open the file in the "none" project or something when building from RStudio template...
Here's a link to the source code for usethis::use_article()
https://github.com/r-lib/usethis/blob/master/R/vignette.R
My hunch from above is the problem is related to usethis::use_article()
attempting to open the new vignette in the editor window. This is hard coded, the code for use_article copied from the link above:
use_article <- function(name, title = name) {
check_is_package("use_article()")
path <- use_vignette_template("article.Rmd", name, title)
use_build_ignore("vignettes/articles")
invisible()
}
use_vignette_template <- function(template, name, title) {
stopifnot(is_string(name))
stopifnot(is_string(title))
use_directory("vignettes")
use_git_ignore(c("*.html", "*.R"), directory = "vignettes")
use_dependency("rmarkdown", "Suggests")
path <- path("vignettes", asciify(name), ext = "Rmd")
data <- project_data()
data$vignette_title <- title
data$braced_vignette_title <- glue::glue("{{{title}}}")
use_template(template,
save_as = path,
data = data,
open = TRUE
)
path
}
The culprit appears to be use_template, which tries to open the vignette. My guess is our bug would be solved if we prevented the opening behavior in the first place. It makes sense to do this because in general there is no good reason to open this particular file for editing on creation of a vertical project.
We could copy these functions and provide modified versions in vertical with the desired behavior (only used on vertical project creation)...I'll also look into devtools to see if there is a function that creates a vignette template with option not to load it in the editor.
Great, I can look into this further later on as well. Just a brief comment: I don't think it's a good idea to copy code from another package. It will make maintaining vertical more problematic in the long run.
Agreed on not copying code...regarding de-bugging I've been spinning and trying various things that didn't solve all the problems. I haven't pushed anything yet but have a few proposals:
path <- file.path(getwd(), path)
Then, create_package()
makes the new folder and adds the R package skeleton
usethis::create_package(path, open = FALSE)
We can do the following to set the path for usethis functions:
usethis::proj_set(path)
At this point, use_git_ignore()
, and use_data_raw()
work properly. But, writing _pkgdown.yml does not (since the working directory wasn't set, the current method instead writes it to the parent directory of the new project, e.g., Desktop).
_pkgdown.yml
to the new folder:usethis::use_template(template = "_pkgdown.yml",
package = "vertical")
However, the remaining init_
functions don't work as intended. They write content to the parent folder, not to the project folder (again because setwd()
was removed).
I guess for now my suggestion is to keep the setwd()
hack in place, and rewrite it as:
setwd(path)
I haven't figured out a different method to let R studio know to write to the new folder. We could try writing everything to a temporary folder, and then copy all of that to a new project folder, but for now I don't really see the advantage of doing that.
Supplementary_1.Rmd
issue, I'm pretty confident this is caused by usethis
, which has no way to prevent the new vignette from opening. Usually you would want it to open for editing, just not in this case. Rather than hacking their code we could submit an issue about this. Basically, using usethis::usearticle()
in the context of setting up an R project template produces unintended behavior, and they could fix that function by allowing an option to prevent the vignette from being loaded in the editor.edit, spoke to soon, I think we can get 3 done using use_template()
, I have a working example, just need to see if I can fit it all together
I just pushed a branch called "testbuild"
I think I solved the Supplementary.Rmd
issue. I used usethis::use_template()
instead, and specified some parameters to name the file, give it a title, etc. The result is the same as before except the file is not opened in the editor. I've tried closing and reopening RStudio, and that file is not loaded.
I also added the changes mentioned above, but kept the setwd(path)
hack in place.
EDIT the branch had some bugs that should be fixed now
I can't check this right now but there is a function, on.exit()
that could be placed somewhere in the function that initializes a vertical project, that could solve some of the problems.
I think this problem is solved now, we can reopen this issue or create a new one if further change is needed.
There is something wrong in
vertical_project()
, leading to the following strange behavior:Supplemental_1.Rmd
file from the recently created vertical project is open. If I had deleted that file, I would get an RStudio error.It most definitely has to do with the fact that the supplemental file is created with
usethis::use_article()
, whereas the other .Rmd docs are created withrmarkdown::draft()
. I have disabled restoring all documents and data from previous sessions so this is undesirable behavior.