R markdown templates#984
Conversation
|
I'm not very familiar with rmd templates, but the ones that were found in my installed packages (rmarkdown, reprex) were only single-file documents. In these instances it might feel more natural to just create an unsaved editor with the content of the file, instead of having to save it somewhere. Would it be feasible to do this for the packages that have |
|
Yes. In my initial implementation, I create untitled documents in all cases, but switched to save before creation when I test with |
| } | ||
|
|
||
| if (template.info.create_dir) { | ||
| const uri = await window.showSaveDialog({ |
There was a problem hiding this comment.
The .Rmd extension might be a bit confusing here. I did not find a really clean solution to configure the SaveDialog to specify a folder, but the following could be used:
let defaultPath = path.join(cwd, 'draft');
let i = 1;
while(fs.existsSync(defaultPath)){
defaultPath = path.join(cwd, `draft_${++i}`);
}
const uri = await window.showSaveDialog({
defaultUri: Uri.file(defaultPath),
filters: {
'Folder': ['']
},
saveLabel: 'Create Folder',
title: 'R Markdown: New Draft'
});The open dialogue seems to have an option to select only folders, but does not allow to select non-existing folders
There was a problem hiding this comment.
Yes, it is something I'm also considering. I tried showOpenDialog with folder-only options, but it didn't work smoothly for saving purpose.
There was a problem hiding this comment.
Also, rmarkdown::draft() will throw error if the target file or folder exists, which I have not handled yet.
There was a problem hiding this comment.
rmarkdown::draft() will create a folder with last file extension removed. For example, draft.Rmd will become draft; draft.test.Rmd will become draft.test.
I update the code to check if this folder already exists and let user confirm whether to remove it before creating the draft folder.
|
@ManuelHentschel Any more suggestions? |
ManuelHentschel
left a comment
There was a problem hiding this comment.
Works nicely, thanks!
What problem did you solve?
Closes #839
This PR implements choosing template and create draft rmd from template via
rmarkdown::draft().The templates are obtained via scanning the R package folders so that the information of all templates are written to a temp JSON file. When user picks a template, saveFileDialog will show up and user needs to find a location to save the file.
Some templates have multiple files. If user specify e.g.
draft.Rmd, multi-file templates will create a new folderdraftand then put files in it.(If you have)Screenshot
Kapture.2022-02-09.at.20.15.37.mp4
(If you do not have screenshot) How can I check this pull request?