I downloaded Processing R Provider plugin (v.1.0.1) which allows us to use R in QGIS 3.4.
Installation and settings were really smooth. This plugin automatically recognizes R installation folder and creates folders for rscripts and user libraries.
However, I encountered an error (Error: '\U' is an unrecognized escape in character string starting) when I tried to run my R scripts (.rsx) ... this may not be an exact translation of the error message; I received it in Japanese (system language).
Working in R on Windows environment, it is not uncommon to encounter back-slash issue. So I tried to replace back-slash by forward-slash, or by double back-slashes. Also tried wrapping the path by " "
and r" "
. None have worked out so far.
Is there any workaround? I am in QGIS 3.4.4 on Windows10 (this issue is probably specific to Windows OS). Attached image is a Providers setting (default setting, automatically generated by the plugin).
This is a sample script I am getting an error:
##Vector Analysis=group
##Layer= vector
##Data= Field Layer
##Data_Name= string data
##showplots
library(ggplot2)
DF <- ggplot(NULL, aes(x= Layer[[Data]])) +
geom_histogram(fill= "white", colour= "black") +
labs(x = Data_Name)
plot(DF)
The Log output is as below. (The tested file meuse_28992.shp
is a shapefile I exported from sp package a while ago. Reprojected to EPSG 28992 and cadmium
is one of its attribute fields.)
Processing algorithm…
Algorithm 'Vector Histogram (ggplot2)' starting…
Input parameters:
{ 'Data' : 'cadmium', 'Data_Name' : 'data', 'Layer' : 'C:/Users/userr/Documents/G/meuse/meuse_28992.shp', 'RPLOTS' : 'C:/Users/userr/AppData/Local/Temp/processing_684f9cfde6cb4d6087ab62a15dce8213/18e098783a5e4e8db9b5545d63a895b7/RPLOTS.html' }
R execution commands
options("repos"="http://cran.at.r-project.org/")
.libPaths("C:/Users/userr/Documents/R/win-library/3.5")
tryCatch(find.package("ggplot2"), error=function(e) install.packages("ggplot2", dependencies=TRUE))
tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", dependencies=TRUE))
tryCatch(find.package("raster"), error=function(e) install.packages("raster", dependencies=TRUE))
library("raster")
library("rgdal")
Layer=readOGR("C:\Users\userr\Documents\G\meuse",layer="meuse_28992")
Data="cadmium"
Data_Name="data"
png("C:/Users/userr/AppData/Local/Temp/processing_684f9cfde6cb4d6087ab62a15dce8213/18e098783a5e4e8db9b5545d63a895b7/RPLOTS.png")
library(ggplot2)
DF <- ggplot(NULL, aes(x= Layer[[Data]])) +
geom_histogram(fill= "white", colour= "black") +
labs(x = Data_Name)
plot(DF)
dev.off()
R execution console output
[1] "C:/Users/userr/Documents/R/win-library/3.5/ggplot2"
[1] "C:/Users/userr/Documents/R/win-library/3.5/rgdal"
[1] "C:/Users/userr/Documents/R/win-library/3.5/raster"
<<1>> 要求されたパッケージ sp をロード中です
rgdal: version: 1.3-6, (SVN revision 773)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/userr/Documents/R/win-library/3.5/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/userr/Documents/R/win-library/3.5/rgdal/proj
Linking to sp version: 1.3-1
<<2>> エラー: ""C:\U" で始まる文字列の中で 8 進文字なしに '\U' が使われています
<<3>> 実行が停止されました
Execution completed in 3.08 seconds
Results:
{'RPLOTS': 'C:/Users/userr/AppData/Local/Temp/processing_684f9cfde6cb4d6087ab62a15dce8213/18e098783a5e4e8db9b5545d63a895b7/RPLOTS.html'}
Loading resulting layers
Algorithm 'Vector Histogram (ggplot2)' finished
HTML output has been generated by this algorithm.
Open the results dialog to check it.
Marked the error messages in Japanese by <<1>>,<<2>>, and <3>>.
- <<1>> Loading required package
sp
. - <<2>> Error: '\U' is an unrecognized escape in character string starting by "C:\U" without octal numbers.
- <<3>> Terminated execution of the process.
I am afraid the translation is not precise enough.
\U
could be from a path or as a Unicode prefix in a string (\U420
is a "P"). I can't tell if the error is coming from QGIS via Python or the R code.... A mystery!C:\Users
was the culprit but I now understand that there are many more possible causes...