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
[v2] Add the toc function with the test failure. #155
Conversation
@JiaxiangBU Great!
This will be the biggest change. By using workflowr-specific functions, you should be able to write the function without adding any new dependencies. The only new dependency you should need to add is clipr.
Of course! Thanks for helping improve workflowr! Please let me know when you are ready for me to review the pull request. |
@jdblischak I follows your tips to use
and pull it, just let you know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming along great! Please see my comments and let me know what questions you have.
R/wflow_toc.R
Outdated
#' @import tibble | ||
#' @export | ||
|
||
wflow_toc <- function(analysis_dir = "analysis", docs_dir = "docs") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only argument the function needs is project = "."
. wflow_status()
returns the paths to these subdirectories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I forget it, I will change it in the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I edit it, here, 8787eed
R/wflow_toc.R
Outdated
#' @export | ||
|
||
wflow_toc <- function(analysis_dir = "analysis", docs_dir = "docs") { | ||
s <- wflow_status() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After adding project = "."
as the default argument to wflow_toc()
, you can change wflow_status()
to wflow_status(project = project)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I will do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I edit it, here, 8787eed
R/wflow_toc.R
Outdated
wflow_toc <- function(analysis_dir = "analysis", docs_dir = "docs") { | ||
s <- wflow_status() | ||
s$status %>% | ||
tibble::rownames_to_column(var = 'rmd_path') %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how to perform these steps without relying on the tidyverse functions? My package doesn't currently use these packages, and I don't want to add a lot of new dependencies for just this one function. If needed, I can translate these to base R commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you. I will try it first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I edit it, but I don't find a good substitute for dplyr::*join
function, do you have any recommendations?
here is my handle, cdbb9c3
R/wflow_toc.R
Outdated
link = glue::glue("1. [{name}]({html_path})") | ||
) %>% | ||
.$link %>% | ||
clipr::write_clip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to make clipr a suggested package. If the user doesn't have clipr installed, then the function can print the results to the R console. Either way it would be good to return the character vector invisibly using return(invisible(x))
, where x
would be replaced with the character vector containing the toc.
You can check if a package is installed using the following strategy:
if requireNamespace("clipr", quietly = TRUE) {
# Write to clipboard
} else {
# Print to R console
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use your recommendation, but I do it in my way because I still get the point of the function invisible
.
In my understanding, if the users have already installed the package clipr
, they will give the toc in their clipboard. If not, the function wflow_toc
will print the toc in the console?
Do I miss something?
Hi @jdblischak , I think I finish most of them, and I am still working on some minimal parts. Now I am trying to update the |
Hi @jdblischak , I think the rmarkdown chunk option
But I don't find a way to set this argument inside the function. Do you know something about it? |
@JiaxiangBU To update |
Hi, @jdblischak I do it and drop most of the tidyverse related packages. |
@JiaxiangBU My mistake. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming along great!
R/wflow_toc.R
Outdated
s <- wflow_status(project = ".") | ||
df<- s$status | ||
df$rmd_path <- rownames(df) | ||
df <- df[df$published] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To filter the rows, this needs to be df <- df[df$published, ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I make a new commit for this editing.
R/wflow_toc.R
Outdated
df<- s$status | ||
df$rmd_path <- rownames(df) | ||
df <- df[df$published] | ||
df$html_path <- to_html(df$rmd_path,outdir = s$docs) %>% basename() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use the pipe %>%
. Instead, either break this into 2 lines:
df$html_path <- to_html(df$rmd_path,outdir = s$docs)
df$html_path <- basename(df$html_path)
or nest the function calls:
df$html_path <- basename(to_html(df$rmd_path,outdir = s$docs))
R/wflow_toc.R
Outdated
df$rmd_path <- rownames(df) | ||
df <- df[df$published] | ||
df$html_path <- to_html(df$rmd_path,outdir = s$docs) %>% basename() | ||
file_name <- sapply(df$rmd_path, function(x) rmarkdown::yaml_front_matter(x)$title) %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is tricky since an Rmd file may not have a title defined. I think it may be best handled with a custom function. Can I send push a commit to your pull request to add this? Then you would get the change locally by running git pull
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that is great, I am looking forward to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try a pull request from your dev
branch to mine and now I know how it works.
R/wflow_toc.R
Outdated
df$link <- paste0("1. [",df$name,"](",df$html_path,")") | ||
|
||
# output | ||
# if (requireNamespace("clipr", quietly = TRUE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be able to view the output even though it is copied to the clipboard, you can return the value of df$link
at the end of the function with return(invisible(df$link))
.
> x <- wflow_toc()
The table of content of your project is on the clipboard.
> x
[1] "1. [About](about.html)" "1. [Home](index.html)" "1. [License](license.html)"
This will also make it easier to write automated tests for wflow_toc()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get your point, so the users expect to get an output in a vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I make a new commit to edit it.
@jdblischak |
I get your point and agree with you. I am thinking about it. When I update the function, I will let you know,. |
Next topic, I find based on this function, the toc is updated manually by users every time. Maybe an automatic solution is better. |
Hi John. I make a new commit for this.
|
@JiaxiangBU Awesome! Good job parsing the YAML file!
I agree that you want to filter the results early.
You don't need to use the here package. I'll update the tests. |
@JiaxiangBU I just pushed two new commits to your branch. Please pull them locally with I changed the filtering to use I also added some tests to catch some edge cases, e.g. when there is no navbar.
Could you please elaborate on this idea? What would happen automatically? |
Thanks, I have a deep understanding of this functon |
I think this change makes this function better, thanks. |
For exmaple, in one of my workflowr project, I add a analysis document by However, in this processs, the toc I think is not updated. the new analysis document is not listed in the toc. Does it make sense to automatically add it in the toc? |
John, I update this package locally by |
@JiaxiangBU Thanks for the explanation. I see how this would be convenient. Unfortunately this would be currently different to implement (i.e. to automatically re-run As a compromise, one option would be to add the following code chunk to
This way, every time you built/published Note: In general running workflowr functions from within an Rmd file is a bad idea, but this works for |
Thus, I think just print a message with the content you write for the users. Users could just paste it in their
Could you please explain this idea? Is there any limitation on the workflowr functions. I am just curious. |
@JiaxiangBU The main workflowr functions like |
@JiaxiangBU I think this PR is ready to merge. Could you please add an entry to Here's an example of a past entry:
Also, would you like to be included as an official contributor? |
I get your point. Thanks for your explanation. |
Codecov Report
@@ Coverage Diff @@
## dev #155 +/- ##
=========================================
+ Coverage 86.93% 87.14% +0.2%
=========================================
Files 25 26 +1
Lines 2871 2863 -8
=========================================
- Hits 2496 2495 -1
+ Misses 375 368 -7
Continue to review full report at Codecov.
|
Hi, John, I make several commits to update news. I find there are several changes from origin dev, when I use |
Yes, I do like it. |
@JiaxiangBU I added you as a contributor in 54b2afb. The function |
This follows the original pull request.
I add my original function in the
dev
branch and pull it into yourdev
branch, just test the git process you show me.And I will follow your tips to edit the function in the two parts,
Just let you know, thank you for your help, I learn a lot from you.