Re: [R] quotation marks and scan
I know you have a solution, but I would have suggested using print() with quote=FALSE as a better way to illuminate what is going on, as in this example: foo - 'bahbah' foo [1] bah\bah print(foo) [1] bah\bah print(foo, quote=FALSE) [1] bahbah As others said, the backslash isn't really there. So you only have to get rid of the which you can do with gsub('','',foo) [1] bahbah To summarize, in R, due to its rules for formatting printed output, what you see isn't always exactly what you have, and this is an example. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/17/13 2:07 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I'm sure that this is a very simple problem, but I have been wresting with it for some time. I have the following file that has the following one line: CRS(+init=epsg:28992) Fair enough. I scan it into R and get the following: u [1] CRS(\+init=epsg:28992\) gsub(pattern='\',replacement='',x=u) [1] CRS(\+init=epsg:28992\) I need to get rid of the extra quotation marks and slashes. I've tried all sorts of things, including gsub, as you see, but no good. Thank you for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] quotation marks and scan
Dear R People: I'm sure that this is a very simple problem, but I have been wresting with it for some time. I have the following file that has the following one line: CRS(+init=epsg:28992) Fair enough. I scan it into R and get the following: u [1] CRS(\+init=epsg:28992\) gsub(pattern='\',replacement='',x=u) [1] CRS(\+init=epsg:28992\) I need to get rid of the extra quotation marks and slashes. I've tried all sorts of things, including gsub, as you see, but no good. Thank you for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quotation marks and scan
(1) The backslashes are not really there; they are an artefact of the R print() function. Try cat(u,\n). I think this might be an FAQ. (2) Is not your problem the fact that your are setting replacement equal to the thing you are trying to get rid of? I.e. don't you want v - gsub(pattern='\',replacement='',x=u) ??? Either I am misunderstanding your intent or you need another cup of coffee. cheers, Rolf On 11/18/13 11:07, Erin Hodgess wrote: Dear R People: I'm sure that this is a very simple problem, but I have been wresting with it for some time. I have the following file that has the following one line: CRS(+init=epsg:28992) Fair enough. I scan it into R and get the following: u [1] CRS(\+init=epsg:28992\) gsub(pattern='\',replacement='',x=u) [1] CRS(\+init=epsg:28992\) I need to get rid of the extra quotation marks and slashes. I've tried all sorts of things, including gsub, as you see, but no good. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quotation marks and scan
They're not actually there so don't try too hard to rid yourself of them: x - \' length(x) print(x) cat(x, \n) Make sure you're clear on the difference between what's stored by the computer and what it print()s. Rarely the same, though cat() is often slightly more honest. On Nov 17, 2013, at 17:07, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I'm sure that this is a very simple problem, but I have been wresting with it for some time. I have the following file that has the following one line: CRS(+init=epsg:28992) Fair enough. I scan it into R and get the following: u [1] CRS(\+init=epsg:28992\) gsub(pattern='\',replacement='',x=u) [1] CRS(\+init=epsg:28992\) I need to get rid of the extra quotation marks and slashes. I've tried all sorts of things, including gsub, as you see, but no good. Thank you for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quotation marks and scan
I actually solved the problem in a backhanded (backslashed?) sort of way...took out the quotation marks in the original file. All is well. Thanks! On Sun, Nov 17, 2013 at 4:38 PM, Rolf Turner r.tur...@auckland.ac.nzwrote: (1) The backslashes are not really there; they are an artefact of the R print() function. Try cat(u,\n). I think this might be an FAQ. (2) Is not your problem the fact that your are setting replacement equal to the thing you are trying to get rid of? I.e. don't you want v - gsub(pattern='\',replacement='',x=u) ??? Either I am misunderstanding your intent or you need another cup of coffee. cheers, Rolf On 11/18/13 11:07, Erin Hodgess wrote: Dear R People: I'm sure that this is a very simple problem, but I have been wresting with it for some time. I have the following file that has the following one line: CRS(+init=epsg:28992) Fair enough. I scan it into R and get the following: u [1] CRS(\+init=epsg:28992\) gsub(pattern='\',replacement='',x=u) [1] CRS(\+init=epsg:28992\) I need to get rid of the extra quotation marks and slashes. I've tried all sorts of things, including gsub, as you see, but no good. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quotation marks and scan
On Sun, Nov 17, 2013 at 10:42 PM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: They're not actually there so don't try too hard to rid yourself of them: x - \' length(x) print(x) cat(x, \n) Did you mean to do 'nchar(x)' to show that \ was one character? 'length' gives the number of elements in a vector, which in this case is also one. x=c(\, '\'') length(x) [1] 2 nchar(x) [1] 1 1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quotation marks and scan
On Sun, Nov 17, 2013 at 6:24 PM, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote: On Sun, Nov 17, 2013 at 10:42 PM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: Did you mean to do 'nchar(x)' to show that \ was one character? 'length' gives the number of elements in a vector, which in this case is also one. x=c(\, '\'') length(x) [1] 2 nchar(x) [1] 1 1 D'oh! Fair enough, MW __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.