cynthiahqy / conformr-xmap-project

R Package for harmonising data of different classifications or aggregations into a single dataset
MIT License
7 stars 1 forks source link

Implement panel map class #43

Closed cynthiahqy closed 1 year ago

cynthiahqy commented 1 year ago

lots of internal functions currently assume inputs are valid panel maps. It would probably be sensible to implement some safeguards -- i.e. using classes

This could be (quickly) checked for using a class condition. Requires implementing a constructor/validation/helper function design pattern as described in 13.3 Classes, Advanced R -- see skeleton here: 27e9ff1/R/panel_map.R

Maybe this lives in a separate panelmap package though?

cynthiahqy commented 1 year ago

This is being implemented in xmap:

cynthiahqy commented 1 year ago

More example code: https://github.com/tidyverts/tsibble/blob/main/R/as-tsibble.R

cynthiahqy commented 1 year ago

What should the s3 object be named?

From Advanced R, 13.3 Classes

When using a class in a package, I recommend including the package name in the class name. That ensures you won’t accidentally clash with a class defined by another package.

But I don't like the look of xmap_xmap, it feels tedious. xmap_df probably makes more sense, because it indicates that it is a data.frame.

cynthiahqy commented 1 year ago

What column type checks are required?

weights should be numeric (<int> or more likely <dbl>)

This one is fairly straight forward, if all links have weight 1 <int> will suffice, otherwise <dbl> is necessary and brings some floating point issues with it (see #30 also)

*_node columns should maybe be factor columns?

From R for Data Science:

In R, factors are used to work with categorical variables, variables that have a fixed and known set of possible values. They are also useful when you want to display character vectors in a non-alphabetical order.

Both the source and target nomenclature form a fixed and known set of possible node labels.

Possible downstream benefits:

But could it cause issues when implementing transformation of data using an xmap?

cynthiahqy commented 1 year ago

Probably want to retain whatever vector class the user provides for the from and to columns. Factor and character vectors make the most sense, but you could have integer codes. This is probably not a great idea, but there isn't any obvious reason xmap should prohibit users from doing this.

cynthiahqy commented 1 year ago

this has been migrated to #57

Where should different checks live?

There are a few types of checks that need to happen when forming a valid xmap:

  1. R specific data.frame/S3 attribute checks
  2. logical conditions on the graph encoded by the xmap
  3. data.frame size/column types

Some of the data.frame attribute checks currently in validate_xmap() are somewhat redundant because they are checked for in new_xmap(). For example:

are all checked when forming the xmap_df.

This means that the error messages in validate_xmap() will never be triggered (since the function takes in an object of class xmap_df.) However, it would still be useful to keep the more verbose error messages currently in validate_xmap() to help users. Maybe I can move these into the as_xmap() helper function?

cynthiahqy commented 1 year ago

Methods & Generics?

More of a later thing, but parking ideas here.

print.xmap()

Existing methods:

The properties of a crossmap that might be useful to display:

plot.xmap()

cynthiahqy commented 1 year ago

Read and Write methods #62 :

cynthiahqy commented 1 year ago

Discussions have all moved to other issues -- mostly #57, #60 and #62