0

Relative R/programming/github novice here, so please excuse my ignorance.

I’m trying to extract a subset of line segments in a line segment pattern based upon a window. Subset.psp aka Extract.psp aka [.psp almost does what I want, except that I would like to exclude the line segments that cross the boundary of the window rather than clipping them.

Example: subset the psp “d” based on the window “eroded” to generate a new psp called “deroded”

> deroded <- d[eroded]
> plot(d, col="blue", main="deroded")
> plot(eroded, add=TRUE, col="red")
> plot(deroded, add=TRUE, col="green")

I am wondering if I can copy most of the functionality of subset.psp and just figure out how to change the trimming part of the function. Now comes the ignorant part: I can’t find the source code for subset.psp. I’ve tried searching on GitHub and in RStudio.

> spatstat:::subset.psp
Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'subset.psp' not found

> getAnywhere(subset.psp)
no object named ‘subset.psp’ was found

I've looked at How can I view the source code for a function?, but I'm having trouble understanding which of the commands apply to subset.psp. What is the proper syntax?

Alternatively, is there a different function or work-around I can use to do this?

Community
  • 1
  • 1
  • Use `spatstat::\`[.psp\`` The title of the help page isn't necessarily the name of the function. `[` is a generic method for which the `spatstat` package provides a method for classes of type `psp`. You find details for generic methods using the form "generic.class." `?"[.psp"` would also bring up the help page. – MrFlick May 09 '17 at 20:13
  • We have interpreted your question as a feature request, and extended the subset operator for `psp` with an argument `fragments` in the development version of `spatstat`. To do what you ask set `fragments = FALSE`. E.g. `copper$SouthLines[square(30), fragments = FALSE]` which returns the 6 segments entirely inside the square as opposed to the default 21 clipped lines. Find spatstat on GitHub for instructions of how to install the development version. Ask a new question if you need a more detailed answer. – Ege Rubak May 10 '17 at 10:09

0 Answers0