When I try to run the R script "Summary statistics" in QGIS 2.12.1 on a Windows 7/64 bit machine, I get the error message "error in if (!file.info(DSN)$isdir) DSN missing value where TRUE/FALSE needed," and the output file is empty.

Having read a comment that R doesn't work properly if installed in the c:\Program Files\ directory, I tried installing it in its own directory in c:, but that didn't make any difference. I've tried installing R with and without the 32 bit files, and with just the 32 bit files (no 64 bit files), but the result is always the same: no results. The same happens with the R Histogram script.

QGIS's native Basic Statistics routine does produce results. Can anyone help me get R scripts working in QGIS?


i don't know the Windows version of R, but from what I know with other OS, you need to access R in the command line.

This mean that you can execute a R script in the console:

R(.exe ?) script.r

What happens when you invoke a R script (as Summary statistics), in Processing ?

1) the script /.../processing/algs/r/RUtils.py first create a R script file with the layer analysed in


2) the content of this script is

tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", dependencies=TRUE))
tryCatch(find.package("raster"), error=function(e) install.packages("raster", dependencies=TRUE))
Layer = readOGR("/yourpath",layer="your_layer")
sd(Layer[[Field]])),row.names=c("Sum:","Count:","Unique values:","Minimum value:","Maximum value:","Range:","Mean value:","Median value:","Standard deviation:"))

3) then the same Python script execute R processing_script.r with the module subprocess

I hope it will help you to understand your problem

| improve this answer | |
  • Thank you for responding. There is a library of R scripts that installs as part of QGIS and is accessible through the processing toolbox. That is what I am trying to get working. I have the latest version of R (3.2.3) installed. – Terry Morse Dec 28 '15 at 4:38
  • I use also this library but the problem, as I say, is the availability of the R executable: R(.exe?) processing_script.r. Can you do that in the command line ? – gene Dec 28 '15 at 9:24
  • When I tried to run the script, I got an invalid syntax error after the line, "tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", dependencies=TRUE))." I don't know whether this is relevant, but I do have rgdal installed at C:\Users\Terry\.qgis2\processing\rlibs\rgdal and have set the path to rlibs correctly in Processing Options. Running the R summary statistics script again, I notice in the output that rgdal is successfully loaded, and the error occurs when it attempts to load the layer (Layer=readOGR(path to the layer). Does this help narrow down the problem any? – Terry Morse Dec 29 '15 at 7:29
  • The correct format in the script is for example Layer = readOGR("/../.../test",layer="test") that is readOGR(path of the shapefile,layer=name of the shapefile (without.shp)) – gene Dec 29 '15 at 9:47
  • I have no experience with Python programming and am not sure what your are suggesting I do. I tried running the script you outlined above with my path, file name, and field name substituted in lines 6 and 7. I get an "invalid syntax" error on line 2. If you have the time and patience, I'll need this spelled out in more detail. Thank you. – Terry Morse Dec 30 '15 at 5:58

While QGIS will extract and process layers from a zipfile, it appears that the R scripts (and possibly others) can't. When I extracted the layers and added them to QGIS, the R summary statistics and histogram scripts worked just fine.

| improve this answer | |
  • What was your layer source? A zipped set of shapefile files (.shp, .shx, .dbf etc)? – Spacedman Dec 30 '15 at 22:44

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.