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

Update initGitbook.R #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

benmarwick
Copy link

This removes this error for me:

Error in if (grepl("r knitsetup.+\n", lines)) { : 
argument is of length zero

Main changes are, first, mdfiles2 <- gsub("\\.md$", ".Rmd", mdfiles) using double backslash to escape the period, so we can rename md files to Rmd, and second,

 toMatch <- c("r knitsetup", "r setup")
 matches <- grepl(paste(toMatch,collapse="|"), lines)  
    suppressWarnings(if (!any(matches)) {

So we get just one TRUE if there are any matches to either r knitsetup or r setup anywhere in the file (or a single FALSE if there is a match), and we can exclude the references.Rmd from this insertion.

Anyway, see if it doesn't break it for you. My details:

sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.5    Rgitbook_0.9

loaded via a namespace (and not attached):
 [1] bibtex_0.3-6        evaluate_0.5.3      formatR_0.10        httr_0.3           
 [5] knitcitations_0.5-0 RCurl_1.95-4.1      rmarkdown_0.1.4     stringr_0.6.2      
 [9] tools_3.0.3         XML_3.98-1.1        xtable_1.7-3  

This removes this error for me:

```
Error in if (grepl("r knitsetup.+\n", lines)) { : 
argument is of length zero
```

Main changes are, first, `mdfiles2 <- gsub("\\.md$", ".Rmd", mdfiles)` using double backslash to escape the period, so we can rename `md` files to `Rmd`, and second, 

```
 toMatch <- c("r knitsetup", "r setup")
 matches <- grepl(paste(toMatch,collapse="|"), lines)  
    suppressWarnings(if (!any(matches)) {
```

So we get just `TRUE` if there are any matches to either `r knitsetup` or `r setup` anywhere in the file, and we can exclude the `references.Rmd` from this insertion.
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.

1 participant