R/as.points.S

Defines functions as.points

Documented in as.points

# Copyright Barry Rowlingson <b.rowlingson@lancaster.ac.uk> and 
# Peter Diggle (c) 1991-3; http://www.maths.lancs.ac.uk/~rowlings/Splancs/
# R port: copyright 1998-2000 by Roger S. Bivand

as.points <- function(...)
{
	nv <- nargs()
	fargs <- list(...)
	if(nv==2){
		l1 <- length(fargs[[1]])
		l2 <- length(fargs[[2]])
		if(l1==l2){
			pts <- cbind(fargs[[1]],fargs[[2]])
		}
		else{
			stop("Cannot make points from different length vectors")
		}
		
	}
	else{
		if(nv==1){
# 111105
                        if (is.data.frame(fargs[[1]]))
                            fargs[[1]] <- as.list(fargs[[1]])
			if(is.list(fargs[[1]])){
				fargs <- fargs[[1]]
				if(any(names(fargs)=="x") & any(names(fargs)=="y")){
					arx <- fargs$x
					ary <- fargs$y
					if(length(arx)!=length(ary)){
						stop("Cannot make points from different length x and y list components!")
					}
					else{
						pts <- cbind(arx,ary)
					}
				} else if (length(fargs) == 2) {
# 110819
                                        pts <- do.call("cbind", fargs)
                                        warning("List/data.frame components should be named x and y")
				} else {
					stop("Cannot make points from list without x and y components.")
				}
			}
			else{
				if(is.points(fargs[[1]]))pts <- fargs[[1]]
				else stop("Cannot make points from this object")
			}
		
		}
		else{
			stop("Cannot make object into points!")
		}
	}

	pts
}

Try the splancs package in your browser

Any scripts or data that you put into this service are public.

splancs documentation built on April 18, 2022, 3 a.m.