Skip to content

paste(" /" ") and paste(" /' ") for grass command

4 messages · Jaime R. Garcia Marquez, Agustin Lobo, Greg Snow

#
I wish to write  "" using paste(), but
[1] "\"Hola\""
while the same approach works with ''
[1] "'Hola'"

why this difference? how could I do it to get "Hola" ?

I need this to write this string in R:
v.extract codigo_Montseny07_clump out=extract11917 where="(GRIDCODE = 
11917)"

and pass it to grass. Something like:
for (i in polis){
    system("g.region vect=codigo_Montseny07_clump")
    nomextract <- paste("extract",i,sep="")
    grcomm <- paste("v.extract codigo_Montseny07_clump out=",nomextract, 
" where=\"(GRIDCODE = ",i,")\" ",sep="")
    system(grcomm)

...

Thanks

Agus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alobolistas.vcf
Type: text/x-vcard
Size: 251 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090422/f11fa9e9/attachment.vcf>
#
Dear Agustin,

I think that using the script paste("\"","Hola","\"",sep="") will do the  
job anyway. Yes, you would get "\"Hola\"" as a result but when you pass  
the script to GRASS the \ symbol will not be considered and so you will  
get the string you are looking for.

a <- "v.extract codigo_Montseny07_clump"
b <- paste("out=extract", 11917, sep="")
c <- paste("(GRIDCODE = ", 11917, ")", sep="")
c <- paste("where=\"", c, "\"",sep="")

string <- paste(a,b,c, sep=" ")
system(string)
[1] "v.extract codigo_Montseny07_clump out=extract11917 where=\"(GRIDCODE  
= 11917)\""

When the command is read in GRASS the \ symbol will mean move to the next  
line in the console.

Best,

Jaime -R


On Wed, 22 Apr 2009 10:31:55 +0200, Agustin Lobo <alobolistas at gmail.com>  
wrote:
#
True. Also, actually grass accepts where='(GRIDCODE = 11917)', so the 
practical problem is solved.
Nevertheless, I find odd the different behavior of

paste("\"","Hola","\"",sep="")
and
paste("\'","Hola","\'",sep="")

the former printing the \
while the second one does not.

Thanks!

Agus
Jaime R. Garcia Marquez wrote:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alobolistas.vcf
Type: text/x-vcard
Size: 251 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090423/a8198f9e/attachment.vcf>
#
It is not the paste function (as has been mentioned before), but the print function that is doing different things.  The default behavior for printing character strings is to put "" around each string, if there is a " inside the string, then the print function will put the \ in the representation to show that it is part of the string.

Since you don't do anything with the results of paste, the print function is called on the result with the default values.  But if you call print yourself with quote=FALSE or use the cat function instead of print (or save the value to a string and look at it in a different way, etc.) then you will see the string with the " and without the \.