R blogdown new_site() throws error - r

If I try to run blogdown::new_site() I get an error message I suspect being a linux/windows conversion problem of slashes maybe?
blogdown::new_site()
Congratulations! Your new Hugo site is created in D:\Documents\Blog.
Just a few more steps and you're ready to go:
1. Download a theme into the same-named folder.
Choose a theme from https://themes.gohugo.io/, or
create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
with "hugo new <SECTIONNAME>\<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".
Visit https://gohugo.io/ for quickstart guide and full documentation.
trying URL 'https://github.com/yihui/hugo-lithium-theme/archive/master.zip'
Content length 119078 bytes (116 KB)
downloaded 116 KB
Error in gsub(tmpdir, ".", zipdir) :
invalid regular expression '.\3aec55bc496d', reason 'Invalid back reference'
Don't quite get what's going on there... I the command on an empty directory and tied it via Rstudio also trying a different template gcushen/hugo-academic which caused the same error message...
I'm running R on a windows machine an all packages are up to date I believe...
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] blogdown_0.5.9
loaded via a namespace (and not attached):
[1] compiler_3.4.3 bookdown_0.7 tools_3.4.3 yaml_2.1.18 knitr_1.20 xfun_0.1

As mentioned in my comment, this was indeed a bug in blogdown tracing back to differences in how Windows and Unix handle slashes in path names (or more specifically, differences in how tempfile() and utils::unzip() handle slashes in their output on Windows).
The issue should now be fixed as of version 0.5.10 of blogdown, which you can install using devtools::install_github("rstudio/blogdown").

Related

read_pptx() throwing error when trying to read a pptx template file

I am trying to generate a report using a template .pptx file provided to me (originally within a zipped folder, which I extracted and saved locally).
R is giving me the following error when I run this code:
doc <- read_pptx('template_files/empty_template/RL_Template.pptx')
Error in tmp_names[match(old_, tmp_names)] <- new_ :
NAs are not allowed in subscripted assignments
The file RL_Template.pptx is a powerpoint template that will be populated with text and images. All scripts, data files, and templates are contained inside an R project, again, saved locally.
I have tried to execute the same line of code on a different machine of mine and get the same error, although a collaborator can successfully download/unzip the same files, run the same code, and generate the appropriate powerpoint output. He and I are running the same versions of R and RStudio.
I can successfully run this line of code to create a new object in R:
foo<-read_pptx()
and can add content to foo using add_slide()
I have updated all associated packages. I have full admin privileges on my machine so it should not be an error with read/write permissions.
It seems like maybe a problem with zip? Any ideas would be appreciated.
Session info:
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.8.4 readxl_1.3.1 flextable_0.5.7 officer_0.3.6 SWMPrExtension_1.1.2 SWMPr_2.3.1
[7] zoo_1.8-7 ggplot2_3.2.1

Package-specific utils::news() not working in RStudio

I'm trying to bring up news for a package while in RStudio. While the default utils::news() works for generating the base R changelog in the built-in viewer, I can't get it to work for a specific package; it throws an error. The function works fine for specific packages in RGui.
Fresh R session in RStudio 1.2.1335:
news() # this works
news(package = "ggplot2") # this doesn't
Error that I get in viewer: Error in UseMethod("toHTML") : no applicable method for 'toHTML' applied to an object of class "NULL"
Fresh R session in RGui:
news()
news(package = "ggplot2") # both work perfectly
Session info:
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0 Rcpp_1.0.1 xml2_1.2.0 commonmark_1.7
How can I get the function to output without error in RStudio? If this is not possible, how can I run the function in RStudio but tell it to view the HTML outside of the viewer, e.g., in the browser like RGui?
This looks like an RStudio bug, so probably the best action is to report it to them. As a workaround, you can avoid using their built-in browser by changing the setting for options("browser").
For example, on a Mac outside of RStudio I see
options("browser")
# $browser
# [1] "/usr/bin/open"
and in RStudio running
options(browser = "/usr/bin/open")
disables the built-in browser. I don't know what it defaults to in RGui on Windows, but setting it to the same in RStudio as it is in RGui should get it to work.
Unfortunately, this disables it for everything, not just for news(), so you probably want something like this instead:
save <- options(browser = "/usr/bin/open")
news(package = "ggplot2")
options(save)

Unable to install Github packages in R

I need a packages witch is located on Github. And I am aware that there are multiple solutions to install the package in R.
I am trying to install the package on a Windows server. This is what I tried:
Solution 1 (which is based on the Vignette)
install.packages("devtools")
library("devtools")
devtools::install_github("bmschmidt/wordVectors")
Error: Could not find tools necessary to compile a package
In addition: Warning messages:
1: In strptime(xx, f, tz = tz): unable to identify current timezone 'C':
Please set environment variable 'TZ'
I tried many things to solve this:
Reinstalling Devtools, use the CRAN devtools version
Reinstalling R and Rstudio (installing the latest versions as admin) (Error : Could not find build tools necessary to build)
But still the same error...
So I tried a workaround to install the packages on my computer:
Solution two
Download ZIP file from (https://github.com/bmschmidt/wordVectors)
Unzip the ZIP file
But the result is an error again:
library(devtools)
install("path/to/unzipped/file")
library("wordVectors")
Error there is no packages called wordVectors.
Anyone an idea what is going on? I struggled the whole day with this issue. Help is really appreciated! Thanks!
Edit
Also Rtools is (re)installed (the latest version...)
Edit 2
As requested in the comments (#DJV):
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.2 tools_3.5.2

RStudio blogdown generates error after using new_site()

After successfully loading blogdown and installing Hugo, I have trouble creating a new site with new_site(dir = 'test') in an empty 'test' folder. First, I get the following positive message:
Congratulations! Your new Hugo site is created in C:....\Dropbox\test.
Just a few more steps and you're ready to go:
Download a theme into the same-named folder.
or create your own with the "hugo new theme " command.
Perhaps you want to add some content. You can add single files
with "hugo new \.".
Start the built-in live server via "hugo server".
trying URL 'https://github.com/yihui/hugo-lithium-theme/archive/master.zip'
Content type 'application/zip' length 119666 bytes (116 KB)
downloaded 116 KB
Now comes the error msg.
Error in list.files(dir) : invalid 'path' argument
The current R session info gives this:
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] blogdown_0.0.35
loaded via a namespace (and not attached):
[1] bookdown_0.3.19 tools_3.3.2 rstudioapi_0.6 knitr_1.15.20
Any idea what I am doing wrong?
This should be a temporary bug that existed for a couple of hours. Please reinstall blogdown from Github:
devtools::install_github('rstudio/blogdown')

Warning whenever I run sourceCpp

I am having trouble running Rcpp on my PC in RStudio. Whenever I sourceCpp() a cpp file, even the Hello World file that comes with Rcpp::Rcpp.package.skeleton(), I get the warning
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]=".../anRpackage/src/../inst/include": The system cannot find the path specified
I searched Stackoverflow and it looks like some people get this warning if they don't have Depends: Rcpp in the DESCRIPTION of their package, but I am just running sourceCpp() so the DESCRIPTION file shouldn't matter (I also changed my DESCRIPTION file).
It is just a warning so the class and functions I wrote do appear in R, but RStudio frequently crashes after I use the functions in R a few times, which may or may not be related.
My session info:
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Rcpp_0.12.1 RevoUtilsMath_7.4.1 RevoUtils_7.4.1 RevoMods_7.4.1 RevoScaleR_7.4.1 lattice_0.20-30 rpart_4.1-9
loaded via a namespace (and not attached):
[1] codetools_0.2-10 foreach_1.4.2 grid_3.1.3 iterators_1.0.7 tools_3.1.3
I suppose it is possible that Revolution R is the culprit here, but I have no way of knowing. I would appreciate help, because I don't want to ignore this warning, and it's obviously not ideal for RStudio to crash repeatedly.
Kind Regards
This is still relevant today, so here's my discoveries.
Rcpp can generate interfaces to and from C++ and R.
These are generated with the help of attributes specified in source-files.
From these attributes, the call to Rcpp::compileAttributes() produces the headers. Whilst at it, this also create the folder <package directory>/inst/include. If you have specified no attributes, anywhere, then compileAttributes() does not create these directories.
In order to get rid of this warning, create the <package directory>/inst/include.
For more on attributes, see Rcpp attributes vignette.

Resources