Skip to content

how to type long string

11 messages · Guoqiang Wang, Duncan Murdoch, Bill Oliver +3 more

#
Hi, All:

I try to type some long string in R console, whenever
I like to change to a new line, I get error message.

The following is my simple code
--------------------------------------
h3 <- sqlQuery(myConnect, "select * from console where

Error: syntax error
byday = 'dd1'group by by hour") 
Error: syntax error

---------------------------------------

Any Hints?

Thanks.

Grant, UWO

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Guoqiang Wang <guo52717 at yahoo.com> writes:
You just can't do that... If SQL allows newlines in expressions, you
could do

h3 <- sqlQuery(myConnect, "select * from console where \
 byday = 'dd1' group by hour")

(Since
+ n"
[1] "a\nn"
)

Otherwise you need an explicit paste(), as in

querystr <- paste("select * from console where",
                  "byday = 'dd1' group by hour")
h3 <- sqlQuery(myConnect, querystr)
#
On Sat, 14 Jul 2001 11:08:48 -0700 (PDT), you wrote:

            
There are two ways.  End each line with a backslash, i.e.

  s <- 'Start of long string\
second line of long string'

This puts a \n in the string.  I don't know if there's a way to avoid
that on input, but you case use paste:

 s <- paste('Start of long string',
'second part of long string')

Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Guoqiang Wang wrote:
Don't use more than one line for each (quoted) string.
The following lines should work:

  h3 <- sqlQuery(myConnect, 
    "select * from console where yday = 'dd1' group by by hour")


Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
----- Original Message -----
From: "Guoqiang Wang" <guo52717 at yahoo.com>
To: <r-help at lists.R-project.org>
Sent: Saturday, July 14, 2001 12:08 PM
Subject: [R] how to type long string
Normally, one can use "+" as a continuation character. Because you are in
the midst of typing a string the continuation character won't work in this
instance. You could perhaps use "paste" to join together the pieces of the
query. For example-
+ "foo > 20 order by foobar"))

-Bill



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
----- Original Message -----
From: "Guoqiang Wang" <guo52717 at yahoo.com>
To: <r-help at lists.R-project.org>
Sent: Saturday, July 14, 2001 12:08 PM
Subject: [R] how to type long string
Sorry. I was mistaken about the continuation character in the last message.
The "+" merely shows up to indicate the continuation of the line. You could
paste to together the pieces of the query this way (no "+" at the end of the
line).
+ "foo > 20 order by foobar"))

Perhaps someone will have a better suggestion.

-Bill


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
John Williams <jwilliams at business.otago.ac.nz> writes:
Doesn't look like something to be embarrassed about... (Uwe, you might
want to add this to one of the examples).

As far as I can see the key would be to use the points3d() function
returned by scatterplot3d(). Something like:

model <- lm(....)
s <- scatterplot3d(....)

for (x in seq(...)) {
    line.x <- rep(x,2)
    line.y <- c(ymin, ymax)
    line.z <- predict(model, new = data.frame(x=line.x, y=line.y)
    s$points3d(line.x, line.y, line.z, type="l", lty="dotted")
}
for (y in seq(....)) {
    ...
}

Alternatively, you might generate the endpoints for a segments() call 
by first producing the coordinates in 3d using predict and then
convert them with s$xyz.convert(). That'd be

d1<-rbind(data.frame(x=xmin,y=seq(...)), data.frame(x=seq(...),y=ymin)
d2<-rbind(data.frame(x=xmax,y=seq(...)), data.frame(x=seq(...),y=ymax)
p1 <- predict(model, new=d1)
p2 <- predict(model, new=d2)

line.begin <- s$xyz.convert(d1$x,d1$y,p1)
line.end <- s$xyz.convert(d2$x,d2$y,p2)

segments(line.begin$x,line.begin$y,line.end$x,line.end$y, lty="dotted")


[As you may have gathered, none of this is actually tested...]
#
Peter Dalgaard BSA wrote:
Thank you, Peter. If I have got some more time, I will do (see below).
Both ideas are very nice. I think predict() has to be used slightly
different.

Nevertheless, in the morning I begun writing a (now tested) example,
also using xyz.convert(). Here is the modified example 5 from the help:

 library(scatterplot3d)
 data(trees)
 attach(trees)
 s3d <- scatterplot3d(trees, type = "h", highlight.3d = TRUE,
     pch=16, main="scatterplot3d -- example 5", angle=60, scale.y=0.7)
 # I want to draw this regression plane as a grid:
 my.lm <- lm(Volume ~ Girth + Height)   
 my.pred <- function(x, y, model){
    my.coef <- coef(model)
    return(my.coef[1] + x * my.coef[2] + y * my.coef[3])
 }
 
 # Now drawing segments from (x1, y1, z1) to (x2, y2, z2). 
 # Looking at the existing plot helps to find the points at first:
 
 x1 <- seq(8, 22, 2)  # Girth
 y1 <- rep(60, 8)     # Height
 z1 <- my.pred(x1, y1, my.lm)
 x2 <- seq(8, 22, 2)
 y2 <- rep(90, 8)
 z2 <- my.pred(x2, y2, my.lm)

 # Now calculating the 3d -> 2d projection for the existing plot
 seg1 <- s3d$xyz.convert(x1, y1, z1)
 seg2 <- s3d$xyz.convert(x2, y2, z2)
 segments(seg1$x, seg1$y, seg2$x, seg2$y, lty="dashed")

 # As above, but the orthogonal lines of the grid:
 x1 <- rep(8, 7)        # Girth
 y1 <- seq(60, 90, 5)   # Height
 z1 <- my.pred(x1, y1, my.lm)
 x2 <- rep(22, 7)
 y2 <- seq(60, 90, 5)
 z2 <- my.pred(x2, y2, my.lm)
 seg1 <- s3d$xyz.convert(x1, y1, z1)
 seg2 <- s3d$xyz.convert(x2, y2, z2)
 segments(seg1$x, seg1$y, seg2$x, seg2$y, lty="dashed")



That's a workaround if you only want to plot it once, but surely
automating it would be nicer. One can also think about drawing
non-linear planes. Maybe this will become a additional function for the
package.

If there a any questions remaining, feel free to send a private mail.

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
I'm a bit embarrassed to ask this, but can anyone tell me (or point me
to a reference) on how to plot a regression plane in R?

I have a regression model with two independent variables and have
created a nice 3d scatterplot with scatterplot3d (thanks Uwe!) and now
would like to overlay the regression plane (gridded, preferably.)  Ay
pointers would be appreciated.

cheers,

John
#
Thanks for all your help from R network.

I really feel at home here.

The problem of long string has been solved, by
following the 'paste' suggestion.

Now I have another problem. I try to make a cross
table of the following dataset.
---------------------------------------------
cell     response    resp.mth         income       
age          province   
 1:4352   0:3122   Min.   :0.000   0-31k  :1475   0-21
:   2   ON     :4064  
 2:1916   1:3146   1st Qu.:0.000   31k-43k:1562  
21-34:1659   BC     : 700  
                   Median :1.000   43k-59k:1567  
34-41:1568   AB     : 459  
                   Mean   :1.316   59k-75k: 905  
41-49:1438   NS     : 303  
                   3rd Qu.:3.000   75k+   : 662   49+ 
:1601   MB     : 297  
                   Max.   :6.000   NA's   :  97       
        NB     : 180  
                                                      
        (Other): 265  
       tenure        acctcnt             fundsp    
ont     
 0-0.67   :  16   Min.   : 0.000   0-1.5k   :1404  
0:2204  
 0.67-1.5 :1645   1st Qu.: 3.000   1.5k-4.4k:1568  
1:4064  
 1.5-1.92 :1775   Median : 3.000   4.4k-10k :1566     
     
 1.92-2.33:1218   Mean   : 3.169   10k+     :1567     
     
 2.33+    :1614   3rd Qu.: 4.000   NA's     : 163     
     
                  Max.   :13.000                     

----------------------------------------
If I use table functions, the level "NA's" in income
and "other" in acctcnt won't appear in the table
regardless of my efforts.
, , cell = 1

         response
income      0   1
  0-31k   459 585
  31k-43k 524 544
  43k-59k 553 527
  59k-75k 350 290
  75k+    239 201

, , cell = 2

         response
income      0   1
  0-31k   214 217
  31k-43k 242 252
  43k-59k 239 248
  59k-75k 135 130
  75k+    108 114
, , cell = 1

         response
income      0   1
  0-31k   459 585
  31k-43k 524 544
  43k-59k 553 527
  59k-75k 350 290
  75k+    239 201

, , cell = 2

         response
income      0   1
  0-31k   214 217
  31k-43k 242 252
  43k-59k 239 248
  59k-75k 135 130
  75k+    108 114
-------------------------------------------------
How can I include "NA" and "other" in the table?

Thanks you so much.

G. Wang, UWO




__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
13 days later
#
Uwe Ligges wrote:
[SNIP]
There is scatterplot3d_0.3-7 on CRAN now.
scatterplot3d() returns a new function plane3d() now, which is designed
to draw the requested regression plane.

For more details have a look at the help page, particularly at the last
example:

    library(scatterplot3d)
    data(trees)
    s3d <- scatterplot3d(trees, type="h", highlight.3d=TRUE, 
        angle=55, scale.y=0.7, pch=16, main="scatterplot3d - 5")
  # Now adding a regression plane to the "scatterplot3d":
    attach(trees)
    my.lm <- lm(Volume ~ Girth + Height)
    s3d$plane3d(my.lm)


Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._