Dear R experts, I wonder how can one input a string variable in multiple lines in a R script. I've seen solution to the command line continuation in the non-string situation (just continute at the new line). However, that doesn't work for strings because the new line character, "\n", is included in the resultant string. For example, if I type the following in a script: datadir=" X:/level1/level2 /level3/level4/ level5/level6" after executing the script, string variable "datadir" becomes "X:/level1/level2\n/level3/level4/\nlevel5/level6" Someone has suggested to use "paste()" for putting pieces of strings together, but I would like to see if there is any other simpler workaround for multiline string continuation. Best, Erik -- Erik Chang, PhD CIHR Group for Action and Perception The University of Western Ontario Department of Psychology Room 6256 Social Science Centre London, ON, Canada. N6A 5C2 audachang at gmail.com http://ulysses.ssc.uwo.ca/ TEL: 1-519-661-2111 ext. 88190. FAX: 1-519-661-3961
maybe you're looking for: cat(datadir) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Erik Chang <audachang at gmail.com>:> Dear R experts, > > I wonder how can one input a string variable in multiple lines in a R > script. I've seen solution to the command line continuation in the > non-string situation (just continute at the new line). However, that > doesn't work for strings because the new line character, "\n", is > included in the resultant string. For example, if I type the following > in a script: > > datadir=" X:/level1/level2 > /level3/level4/ > level5/level6" > > after executing the script, string variable "datadir" becomes > > "X:/level1/level2\n/level3/level4/\nlevel5/level6" > > Someone has suggested to use "paste()" for putting pieces of strings > together, but I would like to see if there is any other simpler > workaround for multiline string continuation. > > Best, > > Erik > > > > -- > Erik Chang, PhD > CIHR Group for Action and Perception > The University of Western Ontario > Department of Psychology > Room 6256 Social Science Centre > London, ON, Canada. N6A 5C2 > > audachang at gmail.com > http://ulysses.ssc.uwo.ca/ > > TEL: 1-519-661-2111 ext. 88190. > FAX: 1-519-661-3961 > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
May this: gsub("\n", "", " X:/level1/level2 /level3/level4/ level5/level6 ") On 10/18/06, Erik Chang <audachang at gmail.com> wrote:> Dear R experts, > > I wonder how can one input a string variable in multiple lines in a R > script. I've seen solution to the command line continuation in the > non-string situation (just continute at the new line). However, that > doesn't work for strings because the new line character, "\n", is > included in the resultant string. For example, if I type the following > in a script: > > datadir=" X:/level1/level2 > /level3/level4/ > level5/level6" > > after executing the script, string variable "datadir" becomes > > "X:/level1/level2\n/level3/level4/\nlevel5/level6" > > Someone has suggested to use "paste()" for putting pieces of strings > together, but I would like to see if there is any other simpler > workaround for multiline string continuation. > > Best, > > Erik > > > > -- > Erik Chang, PhD > CIHR Group for Action and Perception > The University of Western Ontario > Department of Psychology > Room 6256 Social Science Centre > London, ON, Canada. N6A 5C2 > > audachang at gmail.com > http://ulysses.ssc.uwo.ca/ > > TEL: 1-519-661-2111 ext. 88190. > FAX: 1-519-661-3961 > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Possibly Parallel Threads
- how to use chi-square to test correlation question
- how to convert multiple dummy variables to 1 factor variable?
- [LLVMdev] "Recursive compilation detected" and signals
- testing two-factor anova effects using model comparison approach with lm() and anova()
- [LLVMdev] Closures, newbie question