Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dcooley/geometries
R package for creating and manipulating geometric data structures
https://github.com/dcooley/geometries
Last synced: 4 months ago
JSON representation
R package for creating and manipulating geometric data structures
- Host: GitHub
- URL: https://github.com/dcooley/geometries
- Owner: dcooley
- License: other
- Created: 2020-04-27T10:14:29.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-06T13:13:39.000Z (about 1 year ago)
- Last Synced: 2024-10-12T21:28:07.356Z (4 months ago)
- Language: C++
- Homepage: https://dcooley.github.io/geometries/
- Size: 331 KB
- Stars: 28
- Watchers: 4
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.Rmd
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
editor_options:
chunk_output_type: console
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#",
fig.path = "man/figures/README-",
out.width = "100%"
)library(geometries)
```# geometries
[](https://github.com/dcooley/geometries/actions)
[]( https://app.codecov.io/gh/dcooley/geometries?branch=master)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`
```{r}
df <- data.frame(
id = c(1,1,1,1,1,2,2,2,2,2)
, x = 1:10
, y = 10:1
)
df
```You can make two "LINE"* objects by splitting this into a list of matrices
```{r}
gm_geometries(
obj = df
, geometry_cols = c("x","y")
, id_cols = c("id")
)
```*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
```{r}
gm_geometries(
obj = df
, geometry_cols = c("x","y")
, id_cols = c("id")
, class_attributes = list(class = "my_new_shape", other = "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](https://github.com/dcooley/geometries/blob/master/DESCRIPTION#L17) section in the DESCRIPTION field of this package
```yaml
SystemRequirements: C++11
LinkingTo:
Rcpp
Imports:
Rcpp
```This tells the compiler I want to link to Rcpp's. Which means I can use all the [Rcpp code](https://github.com/RcppCore/Rcpp/tree/master/inst/include/Rcpp) by including whichever header file I want.