package

# r-geometries

Description

Convert Between R Objects and Geometric Structures.

Description
Geometry shapes in 'R' are typically represented by matrices (points, lines), with more complex shapes being lists of matrices (polygons). 'Geometries' will convert various 'R' objects into these shapes. Conversion functions are available at both the 'R' level, and through 'Rcpp'.

# geometries

Have you every wanted to generate geometric structures from data.frames, but independent of any R classes, attributes or libraries?

No? Ok, this library isn’t for you.

But if you answered ‘yes’, this might be of interest.

## What is the point?

When one thinks of ‘shape’ objects in R, the current standard / typical structures are

• Point - a vector of x, y values
• Line - a matrix of x, y columns
• Polygon - a list of matrices of x, y columns
• MultiPolygon - a list of list of matrices of x, y columns

(in reality you can have more than just x & y columns)

But constructing these can sometimes be a bit fiddly.

So my goal of this package is to take away the pain of building shapes. I want to accept any base R data object and convert it into the required shape

## Some Examples

Take a `data.frame`

``````df <- data.frame(
id = c(1,1,1,1,1,2,2,2,2,2)
, x = 1:10
, y = 10:1
)
df
#    id  x  y
# 1   1  1 10
# 2   1  2  9
# 3   1  3  8
# 4   1  4  7
# 5   1  5  6
# 6   2  6  5
# 7   2  7  4
# 8   2  8  3
# 9   2  9  2
# 10  2 10  1
``````

You can make two “LINE”* objects by splitting this into a list of matrices

``````gm_geometries(
obj = df
, geometry_cols = c("x","y")
, id_cols = c("id")
)
# [[1]]
#      [,1] [,2]
# [1,]    1   10
# [2,]    2    9
# [3,]    3    8
# [4,]    4    7
# [5,]    5    6
#
# [[2]]
#      [,1] [,2]
# [1,]    6    5
# [2,]    7    4
# [3,]    8    3
# [4,]    9    2
# [5,]   10    1
``````

*I’ve put “LINE” in quotes because this doesn’t have to be called a LINE, it’s just that a LINE is typically represented by a matrix in R.

And if you send it a `class_attribute`, you can make it into whatever type of object you want

``````gm_geometries(
obj = df
, geometry_cols = c("x","y")
, id_cols = c("id")
, class_attributes = list(class = "my_new_shape", other = "really_awesome_shape")
)
# [[1]]
#      [,1] [,2]
# [1,]    1   10
# [2,]    2    9
# [3,]    3    8
# [4,]    4    7
# [5,]    5    6
# attr(,"class")
# [1] "my_new_shape"
# attr(,"other")
# [1] "really_awesome_shape"
#
# [[2]]
#      [,1] [,2]
# [1,]    6    5
# [2,]    7    4
# [3,]    8    3
# [4,]    9    2
# [5,]   10    1
# attr(,"class")
# [1] "my_new_shape"
# attr(,"other")
# [1] "really_awesome_shape"
``````

And I’m building it as an interface package. That is, it’s all being written in C++ header files, so you can link to these header files from your own package.

## What do you mean, ‘link to’?

When you build a package, if you want to use C++ code from another package, you have to let the compiler know. In an R package, you do this by specifying a `LinkingTo` value in the DESCRIPTION.

Take for example, the LinkingTo section in the DESCRIPTION field of this package

``````SystemRequirements: C++11
Rcpp
Imports:
Rcpp
``````

This tells the compiler I want to link to Rcpp’s. Which means I can use all the Rcpp code by including whichever header file I want.

`0.2.2`

Unknown

### Platforms71 (71)

Darwin
FreeBSD 13
Genode
GHCJS
Linux
MMIXware
NetBSD
none
OpenBSD
Redox
Solaris
WASI
Windows
Show all
• `aarch64-darwin`
• `aarch64-genode`
• `aarch64-linux`
• `aarch64-netbsd`
• `aarch64-none`
• `aarch64_be-none`
• `arm-none`
• `armv5tel-linux`
• `armv6l-linux`
• `armv6l-netbsd`
• `armv6l-none`
• `armv7a-darwin`
• `armv7a-linux`
• `armv7a-netbsd`
• `armv7l-linux`
• `armv7l-netbsd`
• `avr-none`
• `i686-cygwin`
• `i686-darwin`
• `i686-freebsd13`
• `i686-genode`
• `i686-linux`
• `i686-netbsd`
• `i686-none`
• `i686-openbsd`
• `i686-windows`
• `javascript-ghcjs`
• `loongarch64-linux`
• `m68k-linux`
• `m68k-netbsd`
• `m68k-none`
• `microblaze-linux`
• `microblaze-none`
• `microblazeel-linux`
• `microblazeel-none`
• `mips64el-linux`
• `mipsel-linux`
• `mipsel-netbsd`
• `mmix-mmixware`
• `msp430-none`
• `or1k-none`
• `powerpc-netbsd`
• `powerpc-none`
• `powerpc64-linux`
• `powerpc64le-linux`
• `powerpcle-none`
• `riscv32-linux`
• `riscv32-netbsd`
• `riscv32-none`
• `riscv64-linux`
• `riscv64-netbsd`
• `riscv64-none`
• `rx-none`
• `s390-linux`
• `s390-none`
• `s390x-linux`
• `s390x-none`
• `vc4-none`
• `wasm32-wasi`
• `wasm64-wasi`
• `x86_64-cygwin`
• `x86_64-darwin`
• `x86_64-freebsd13`
• `x86_64-genode`
• `x86_64-linux`
• `x86_64-netbsd`
• `x86_64-none`
• `x86_64-openbsd`
• `x86_64-redox`
• `x86_64-solaris`
• `x86_64-windows`
mnos-build-web-prod-20230506T105712Z-2f940cd