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

allow setting header level (per analysis document) of session info chunk #139

Closed
rgayler opened this issue Jan 5, 2019 · 7 comments
Closed

Comments

@rgayler
Copy link

rgayler commented Jan 5, 2019

I enable section number in analysis document because I find it helpful when speaking with remote collaborators to be able to refer to a section number.

The sessioninfo chunk automatically inserted at the end of every analysis document has an H2 header. If I use H1 headers for my sections, then the sessioninfo chunk is rendered as a subsection of my last H1 section, which is usually not logical. If I use H2 for my top level headers, then all the headers are rendered as 0.n, which looks odd.

It would be helpful to be able to specify the header level of the sessioninfo chunk - preferably per analysis file.

@jdblischak
Copy link
Member

I enable section number in analysis document because I find it helpful when speaking with remote collaborators to be able to refer to a section number.

@rgayler That's a great idea!

It would be helpful to be able to specify the header level of the sessioninfo chunk - preferably per analysis file.

I think there are multiple ways to handle this without adding an extra setting. Here are some ideas. Please let me know if you like any of these:

Manually include your own session information chunk

The function wflow_html() will only insert a session information chunk (with an H2 header) if it detects code chunks but no call to sessionInfo() (or session_info() from devtools). Thus one option to include this information while formatting the header is to manually add your own chunk to each file.

For example, this R Markdown file:

---
output:
  workflowr::wflow_html:
    number_sections: true
---

# First section

In this analysis...

# Second section

```{r code}
1 + 1
```

# Session information

```{r session-info}
sessionInfo()
```

Creates the following HTML output:

screenshot from 2019-01-07 10-21-39

Use pandoc offset argument

A second option would be to use H2 headers for subsections along with the pandoc argument --number-offset. This will result in the sections being numbered as 1.1, 1.2, etc.

For example, this R Markdown file:

---
output:
  workflowr::wflow_html:
    number_sections: true
    pandoc_args: ["--number-offset", "1"]
---

## First section

In this analysis...

## Second section

```{r code}
1 + 1
```

Creates the following HTML output:

screenshot from 2019-01-07 10-28-05

@rgayler
Copy link
Author

rgayler commented Jan 7, 2019

Thanks, John. I will almost certainly use option1 (explicitly call sessioninfo), because that has been my standard practice for a while and I generally use devtools::session_info.

@rgayler rgayler closed this as completed Jan 7, 2019
@rgayler
Copy link
Author

rgayler commented Jan 8, 2019

The function wflow_html() will only insert a session information chunk (with an H2 header) if it detects code chunks but no call to sessionInfo() (or session_info() from devtools).

What version of workflowr was that introduced? I am using CRAN workflowr v1.1.1 and don't get that behaviour. I have tried inserting calls to sessionInfo() and devtools::session_info() and even naming the chunk session-info (as in your example) and none of them suppressed the automatic sessinfo.

@rgayler rgayler reopened this Jan 8, 2019
@jdblischak
Copy link
Member

What version of workflowr was that introduced? I am using CRAN workflowr v1.1.1 and don't get that behaviour.

This was introduced in v1.0.0.

I have tried inserting calls to sessionInfo() and devtools::session_info() and even naming the chunk session-info (as in your example) and none of them suppressed the automatic sessinfo.

My apologies. I only gave you half of the solution. The full solution is documented in the section Change the session information function in the vignette Customize your research website. You need to add the entry sessioninfo: "" to the file _workflowr.yml. This will prevent the automatic insertion by workflowr. Once you confirm this works (e.g. with wflow_build() or the Knit HTML button), you can publish (i.e. commit) these changes with wflow_publish("_workflowr.yml", republish = TRUE).

@rgayler
Copy link
Author

rgayler commented Jan 8, 2019

Gotcha. I misinterpreted you as saying that workflowr searched for an occurrence of sessionInfo() in the document code.

Tested. Works. Done. Thanks!

@rgayler rgayler closed this as completed Jan 8, 2019
@jdblischak
Copy link
Member

I misinterpreted you as saying that workflowr searched for an occurrence of sessionInfo() in the document code.

@rgayler Not your fault. I did say that, and I was mistaken. This is because workflowr does search the document code when deciding whether or not the file should pass the reproducibility check (displayed at the top of the file). However, for the mechanism to insert the session info chunk, it currently requires the user to explicitly disable it in _workflowr.yml (perhaps I'll change this strict requirement in the future).

Tested. Works. Done. Thanks!

Glad it's working!

@jdblischak
Copy link
Member

@rgayler Also note that I am considering getting rid of the level 2 header altogether. Instead the Session Information would be included as a collapsible button at the very end of each analysis. See #120 (comment) for discussions and screenshots.

This change is part of an overhaul of the workflowr styling to be less intrusive. See #110 (comment) for how the workflowr report is changing.

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

No branches or pull requests

2 participants