Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible return of wflow_open? #107

Closed
xiangzhu opened this issue Jun 13, 2018 · 17 comments
Closed

Possible return of wflow_open? #107

xiangzhu opened this issue Jun 13, 2018 · 17 comments

Comments

@xiangzhu
Copy link

Hi John -- I am not sure whether I asked you this before. I apologize if this is a redundant issue.

I wonder if the function wflow_open() could possibly be back to the CRAN version. Ideally, if I type wflow_open('new.Rmd'), it will create a file new.Rmd in analysis folder, with the following header template automatically available:

---
title: xxx
author: xxx
date: xxx
output: workflowr::wflow_html
---
@jdblischak
Copy link
Member

@xiangzhu The good news is that I've already started on a re-implementation of wflow_open(). @stephens999 is also interested in this.

Also, based on your previous idea in #100, wflow_open() will try to guess the author name from the Git user.name variable.

I still need to work out some issues with determining the working directory (since in workflowr 1.0+ that can be affected by knit_root_dir in _workflowr.yml). I'll let you know when it's ready for testing.

@jdblischak
Copy link
Member

@xiangzhu Could you please test out the minimal reincarnation of wflow_open()? It's on the "dev" branch:

devtools::install_github("jdblischak/workflowr@dev")

I'd specifically like your feedback on:

  1. The automatically-populated YAML header

  2. Currently there is no magic. Thus if you run wflow_open("new.Rmd") from the root of the project, it creates it in the root of the project. I think this is dangerous, and that a little magic to ensure the file goes to analysis/ is worth it

  3. Suggestions for what information to report after running wflow_open()

@xiangzhu
Copy link
Author

@jdblischak Thanks for the update!

I just tried this new dev feature, and it seems that's exactly what I want!

screen shot 2018-06-21 at 4 44 39 pm

screen shot 2018-06-21 at 4 45 35 pm

Regarding 2, I agree such "magic" is attractive; but I have the habit of setting analysis as the main working directory, and thus 2 is not a big issue for me.

@jdblischak
Copy link
Member

I just tried this new dev feature, and it seems that's exactly what I want!

Awesome! Thanks for testing!

Regarding 2, I agree such "magic" is attractive; but I have the habit of setting analysis as the main working directory, and thus 2 is not a big issue for me.

So you manually set the working directory with setwd or the RStudio menu every time you open a workflowr project? Do you ever use wflow_open to open an existing file, or do you only use it to create new files?

@xiangzhu
Copy link
Author

So you manually set the working directory with setwd or the RStudio menu every time you open a workflowr project?

Sometimes yes and sometimes no. I guess this has to do with which version of workflowr I am using.

Do you ever use wflow_open to open an existing file, or do you only use it to create new files?

I only use it to create new files; for existing files I am using file.edit().

@jdblischak
Copy link
Member

@xiangzhu I made a few more minor updates to wflow_open(). If you have time, please experiment and let me know what you think.

@jdblischak
Copy link
Member

@xiangzhu I am finalizing the new implementation of wflow_open() and will be releasing a new version soon. FYI I made some changes to the functionality in 7417fbe. Since you save your R Markdown files in analysis/, I think it should still be fine for your use case.

@xiangzhu
Copy link
Author

xiangzhu commented Jul 3, 2018

I look forward to the new release!

Since you save your R Markdown files in analysis/, I think it should still be fine for your use case.

I thought that all Rmd files (whose resulting html files will be shown in the website) should be saved in analysis/; did I misunderstand any part?

@jdblischak
Copy link
Member

I thought that all Rmd files (whose resulting html files will be shown in the website) should be saved in analysis/; did I misunderstand any part?

Yes, you are correct that is where they should be saved in order to be included in the website. wflow_open() also allows the creation of an Rmd file in another location if the user sets project = NULL. Probably not used much, but I wanted to allow this possibility.

The main difference you might notice from the previous implementation of wflow_open() is that the filepath must be correct. For example, if you run wflow_open("new.Rmd") from the root of the project, it will throw an error. The correct command would be wflow_open("analysis/new.Rmd"). Since you said that you typically manually switch the working directory to analysis/ anyways, I don't think this will affect you much.

@pcarbo
Copy link
Member

pcarbo commented Jul 3, 2018

I look forward to the new release!

@xiangzhu I believe it is currently implemented in the dev branch if you want to try out the new feature now.

@xiangzhu
Copy link
Author

xiangzhu commented Jul 3, 2018

@jdblischak Thanks for the clarification!

@pcarbo thanks for the info! I am not affected by this new feature and I will wait for the formal release.

@jdblischak
Copy link
Member

@xiangzhu The new wflow_open() is now available in v1.1.0. You can download it now from the master branch, and it will be available on CRAN in the next few days.

@xiangzhu
Copy link
Author

@jdblischak now I understand better one of your replies above

The main difference you might notice from the previous implementation of wflow_open() is that the filepath must be correct. For example, if you run wflow_open("new.Rmd") from the root of the project, it will throw an error. The correct command would be wflow_open("analysis/new.Rmd"). Since you said that you typically manually switch the working directory to analysis/ anyways, I don't think this will affect you much.

> wflow_open(file="grs_compare_logor_chd4_eur.Rmd")
wflow_open:
- New file(s):
  /Users/xiangzhu/GitHub/mvp-cad/analysis/grs_compare_logor_chd4_eur.Rmd
- New working directory: /Users/xiangzhu/GitHub/mvp-cad
> getwd()
[1] "/Users/xiangzhu/GitHub/mvp-cad"

@jdblischak
Copy link
Member

@xiangzhu Right, it changed your working directory to the root of the project, which is now the default for new workflowr projects. You can change this in _workflowr.yml if you'd prefer to have the knit directory be analysis/. See the docs for wflow_html.

@xiangzhu
Copy link
Author

Thanks! I think I will have to get used to this new default root project.

Here is an example -- it just verifies everything you said before! The error message is very clear to me.

> wflow_open("ashlrt_201peca_31trait.Rmd")
Error: Argument "files" specifies at least one file outside the R Markdown source directory:

/Users/xiangzhu/GitHub/rss-peca/ashlrt_201peca_31trait.Rmd

R Markdown files inside your workflowr project must be in the following directory:

/Users/xiangzhu/GitHub/rss-peca/analysis

Set project=NULL to create an R Markdown file outside of the R Markdown directory of your workflowr project. See
?wflow_open for details.
> wflow_open("analysis/ashlrt_201peca_31trait.Rmd")
wflow_open:
- New file(s):
  /Users/xiangzhu/GitHub/rss-peca/analysis/ashlrt_201peca_31trait.Rmd
- Same working directory: /Users/xiangzhu/GitHub/rss-peca

@pcarbo
Copy link
Member

pcarbo commented Jul 20, 2018

@xiangzhu You do not have to get used to the default root---you can override the default in the _workflowr.yml file.

@jdblischak
Copy link
Member

Thanks! I think I will have to get used to this new default root project.

As @pcarbo noted above, you are welcome to either adjust to the new default or continue with the previous setting of executing the code in analysis/. Totally up to you how you'd like to work!

Here is an example -- it just verifies everything you said before! The error message is very clear to me.

I'm glad the error message is informative. Credit to @pcarbo who pays special attention to making sure workflowr error messages are as useful as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants