Skip to content

Instantly share code, notes, and snippets.

@obrl-soil
Created April 14, 2017 06:18
Show Gist options
  • Save obrl-soil/8a0a0114e4333e72d3974961177da7ca to your computer and use it in GitHub Desktop.
Save obrl-soil/8a0a0114e4333e72d3974961177da7ca to your computer and use it in GitHub Desktop.
# documenting some file.path quirks on windows
# gdal translate is used below to copy a file. its on the system PATH, enabling easy access via system2
infile <- 'C:/Data/test.tif'
> setwd('C:/Data/space\\ test')
Error in setwd("C:/Data/space\\ test") : cannot change working directory
> setwd('"C:/Data/space test"')
Error in setwd("\"C:/Data/space test\"") :
cannot change working directory
> setwd('C:/Data/space test')
> outfile <- file.path(getwd(), 'test2.tif')
> system2('gdal_translate', args = c(infile, outfile))
ERROR 6: Too many command options 'test/test2.tif'
Usage: gdal_translate [--help-general] [--long-usage]
[-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/
CInt16/CInt32/CFloat32/CFloat64}] [-strict]
[-of format] [-b band] [-mask band] [-expand {gray|rgb|rgba}]
[-outsize xsize[%]|0 ysize[%]|0] [-tr xres yres]
[-r {nearest,bilinear,cubic,cubicspline,lanczos,average,mode}]
[-unscale] [-scale[_bn] [src_min src_max [dst_min dst_max]]]* [-exponent[_bn] exp_val]*
[-srcwin xoff yoff xsize ysize] [-epo] [-eco]
[-projwin ulx uly lrx lry] [-projwin_srs srs_def]
[-a_srs srs_def] [-a_ullr ulx uly lrx lry] [-a_nodata value]
[-gcp pixel line easting northing [elevation]]*
[-mo "META-TAG=VALUE"]* [-q] [-sds]
[-co "NAME=VALUE"]* [-stats] [-norat]
[-oo NAME=VALUE]*
src_dataset dst_dataset
Warning message:
running command '"gdal_translate" C:/Data/test.tif C:/Data/space test/test2.tif' had status 1
> system2('gdal_translate', args = c(infile, paste0('"', outfile, '"')))
Input file size is 789, 861
0...10...20...30...40...50...60...70...80...90...100 - done.
@bhaskarvk
Copy link

I don't have access to a windows box right now. Does the following work ?

setwd('C:/Data/"space test"')

@obrl-soil
Copy link
Author

sadly no, 'cannot change wd' again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment