Skip to content
This repository has been archived by the owner on Apr 20, 2020. It is now read-only.

Problem with file path in windows #83

Closed
BastienFR opened this issue Sep 28, 2017 · 9 comments
Closed

Problem with file path in windows #83

BastienFR opened this issue Sep 28, 2017 · 9 comments

Comments

@BastienFR
Copy link

Hello,

I've noticed that RQGIS doesn't handle file path correclty when using the \\ in windows.

Example:

library(RQGIS)
monqgis <- set_env("C:\\OSGeo4W64")

params.default.rastercalculator <- get_args_man(alg = "gdalogr:rastercalculator", qgis_env = monqgis)
params <- params.default.rastercalculator
path <- "C:\\Users\\Bastien\\Dropbox\\stackexchange_tranfert\\temp\\"

params$INPUT_A <- paste0(path,"depth_D500.tif")
params$OUTPUT <- paste0(path, "depth_D500b.tif")
params$FORMULA <- "A*2" 
params$RTYPE <- "1"
run_qgis(alg = "gdalogr:rastercalculator", params=params, qgis_env = monqgis)
Error in run_qgis(alg = "gdalogr:rastercalculator", params = params, qgis_env = monqgis) : 
  Unable to execute algorithm
Wrong parameter value: C:\Users\Bastien\Dropbox\stackexchange_tranfert	emp\depth_D500.tif

The error here is caused by the fact that the folder temp starts whit a "t" making the \\temp become \t which is a tab in R. This can be work around by using / instead of \\, however I think it would be more robust to fix this.

Thanks

Bastien

@tim-salabim
Copy link
Member

@BastienFR is there a specific reason you are using \\ instead of / in your path notations? R on Windows handles standard / without any problems afaict.

@BastienFR
Copy link
Author

BastienFR commented Sep 28, 2017

Personnaly, I use the \\ because I found it faster to double my \ than change them to / after my copy paste. Anyway, both are supported in R on windows and I would suspect that they are both almost equally used. Using the \\ is not marginal as you can see in the fonction normalizedPath() which as for its default values the \\ :

normalizePath("C:/this/system/path")
[1] "C:\\this\\system\\path"

@tim-salabim
Copy link
Member

A very good point about how wide spread this use may be. As for copy-paste on windows, path copy copy has made my life so much easier! Let's you copy paths in unix-style so no more \\ or find-replace \ /

@BastienFR
Copy link
Author

path copy copy seems nice! Thanks for the link, I'll check it out!

@jannes-m
Copy link
Collaborator

Python is causing the problem here, not R. Anyways, we fixed this a while ago (commit 484e1d3 and issue #71). Pls install the developer version of RQGIS.

@BastienFR
Copy link
Author

BastienFR commented Sep 29, 2017

Actually, I am using the developer (RQGIS_1.0.1.9000) version. See my sessionInfo:

R version 3.4.1 (2017-06-30)
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  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] bindrcpp_0.2      rgdal_1.2-11      data.table_1.10.4 dplyr_0.7.2       snowfall_1.84-6.1 snow_0.4-2        RQGIS_1.0.1.9000  reticulate_1.0   
 [9] RSAGA_0.94-5      plyr_1.8.4        shapefiles_0.7    foreign_0.8-69    gstat_1.1-5       raster_2.5-8      sp_1.2-5          gdalUtils_2.0.1.7

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12           bindr_0.1              compiler_3.4.1         R.methodsS3_1.7.1      R.utils_2.5.0          iterators_1.0.8       
 [7] xts_0.10-0             tools_3.4.1            jsonlite_1.5           tibble_1.3.3           lattice_0.20-35        pkgconfig_2.0.1       
[13] rlang_0.1.1            foreach_1.4.3          rstudioapi_0.6         DBI_0.7                parallel_3.4.1         stringr_1.2.0         
[19] hms_0.3                grid_3.4.1             glue_1.1.1             spacetime_1.2-0        sf_0.5-4               R6_2.2.2              
[25] readr_1.1.1            udunits2_0.13          magrittr_1.5           RStudioShortKeys_0.1.0 codetools_0.2-15       intervals_0.15.1      
[31] units_0.4-6            assertthat_0.2.0       stringi_1.1.5          FNN_1.1                zoo_1.8-0              R.oo_1.21.0           
 

@jannes-m
Copy link
Collaborator

jannes-m commented Oct 2, 2017

Ok, strange, shouldn't be that way. Ah, I have only changed this behavior if we use st_write() or writeRaster() and not if the user provides the full path, ok, will take care of it.

And in any case it might be useful to adopt the "/" when using Windows, will change set_env() accordingly.

@jannes-m jannes-m reopened this Oct 2, 2017
@jannes-m
Copy link
Collaborator

jannes-m commented Oct 2, 2017

Commit c74af52 should take care of this issue. However, so far I only made sure to normalize the paths under Windows if the input is of type vector, raster or table (which should be the most common use cases).

Interestingly, using / in set_env() leads to trouble when subsequently running open_app(). Will have a look into this, too.

@jannes-m
Copy link
Collaborator

jannes-m commented Oct 2, 2017

set_env() now uses forward slashes (commit 8befac3)

@jannes-m jannes-m closed this as completed Oct 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants