Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Fixed issue where completion tooltip was erroneously shown in multi-line strings in some cases (#8677)
* Fixed issue with autocompletion of column names within native-piped R expressions (#9385)
* Fixed issue where help requests for Python objects would fail with reticulate 1.20 (#9311)
* Fixed issue where R Markdown template skeletons with a '.rmd' extension were not discovered (Pro #1607)

### Misc

Expand Down
10 changes: 6 additions & 4 deletions src/cpp/session/modules/SessionRMarkdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@

# given a path to a folder on disk, return information about the R Markdown
# template in that folder.
.rs.addFunction("getTemplateYamlFile", function(path) {
.rs.addFunction("getTemplateYamlFile", function(path)
{
# check for required files
templateYaml <- file.path(path, "template.yaml")
skeletonPath <- file.path(path, "skeleton")
Expand All @@ -260,11 +261,13 @@
return(NULL)
}

if (!file.exists(file.path(skeletonPath, "skeleton.Rmd")))
# validate that a skeleton.Rmd file exists
paths <- file.path(skeletonPath, c("skeleton.rmd", "skeleton.Rmd"))
if (!any(file.exists(paths)))
return(NULL)

# will need to enforce create_dir if there are multiple files in /skeleton/
multiFile = length(list.files(skeletonPath)) > 1
multiFile <- length(list.files(skeletonPath)) > 1

# return metadata; we won't parse until the client requests template files
list(
Expand All @@ -273,7 +276,6 @@
)
})


.rs.addFunction("evaluateRmdParams", function(contents) {

Encoding(contents) <- "UTF-8"
Expand Down
22 changes: 15 additions & 7 deletions src/cpp/session/modules/rmarkdown/SessionRMarkdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,19 +1301,27 @@ Error getRmdTemplate(const json::JsonRpcRequest& request,

json::Object jsonResult;

// locate the template skeleton on disk (if it doesn't exist we'll just
// return an empty string)
FilePath skeletonPath = FilePath(path).completePath("skeleton/skeleton.Rmd");
// locate the template skeleton on disk
// (return empty string if none found)
std::string templateContent;
if (skeletonPath.exists())
for (auto&& suffix : { "skeleton/skeleton.Rmd", "skeleton/skeleton.rmd" })
{
error = readStringFromFile(skeletonPath, &templateContent, string_utils::LineEndingPosix);
FilePath skeletonPath = FilePath(path).completePath(suffix);
if (!skeletonPath.exists())
continue;

Error error = readStringFromFile(skeletonPath, &templateContent, string_utils::LineEndingPosix);
if (error)
return error;
{
LOG_ERROR(error);
continue;
}

break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this logic is correct -- it looks like skeleton/skeleton.rmd will never be read except under very unusual circumstances (the Rmd version exists but can't be read). Am I misreading this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you are correct. I've fixed this up now.

}

jsonResult["content"] = templateContent;
pResponse->setResult(jsonResult);

return Success();
}

Expand Down