Skip to content

Conversation

@JhossePaul
Copy link

I found an error while trying to compile an roxygenized package in Windows when the Collate directive was added to the DESCRIPTION file. The problem is that the package_files function returns the path to the directory if there are leading whitespaces in the DESCRIPTION file.

I would recommend to change the scan function for regular expressions as they are safer and have full control under the string.

For example, if

desc <- list(Collate = "'bar.R'\n    'foo.R'")
collate <- scan(text = desc$Collate, what = "", sep = " ")
collate
[1] "bar.R" ""      ""      ""     ""    "foo.R"

then;

> file.path("path_to_package", "R", collate)
[1] "path_to_package/R/bar.R" "path_to_package/R"       "path_to_package/R"       "path_to_package/R"      
[5] "path_to_package/R"       "path_to_package/R/foo.R"

If we pass this paths to the tokenize_file function, it will throw an error. I propose:

unlist(strsplit(gsub("'", "", desc$Collate), "\\n\\s*"))
[1] "bar.R"  "foo.R"

scan(..., sep = " ") will create empty strings if there are leading whitespaces in the DESCRIPTION file, thus generating an error when trying to apply tokenize_file to unexisting files. Using regular expressions because they are safer than scan
@hadley
Copy link
Member

hadley commented Aug 21, 2018

Can you please start by filing an issue describing the problem?

@hadley hadley closed this Aug 21, 2018
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

Successfully merging this pull request may close these issues.

2 participants