5

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).

enter image description here

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.

  • Did the error say anything about which line of what file caused the error? – Spacedman Jan 26 at 8:39
  • @Spacedman Unfortunately no. In the Log panel, the error message appears immediately after loading libraries such as ggplot2, rgdal, raster and sp. (The ggplot2 is called by my rscript, others are default). I will edit the question to include a test script. – Kazuhito Jan 26 at 8:53
  • Anyway you can change your language to English and post the exact text? \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! – Spacedman Jan 26 at 11:05
  • Thanks so much @Spacedman for your help. Copied Log output. Messages in Japanese language were added as footnotes. I had been thinking C:\Users was the culprit but I now understand that there are many more possible causes... – Kazuhito Jan 26 at 11:32
  • 1
    I think it is possibly the same isse as this: gis.stackexchange.com/questions/228074/… - the layer source path has \U and when that is passed to R it fails. There are some suggestions in that post. – Spacedman Jan 26 at 14:48
2

This is fixed in the latest version of the plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.