actel icon indicating copy to clipboard operation
actel copied to clipboard

Add documentation for example code for distancesMatrix where user already has t.layer and spatial objects loaded in environment

Open SimonDedman opened this issue 1 year ago • 1 comments

Would be nice for users to have a guide for how to do this, given I expect a standard workflow will be to create objects in order, following the manual. And therefore to have all objects in the environment. Example:

distances <- actel::distancesMatrix(
  t.layer = t.layer,
  starters = spatial,
  targets = spatial,
  coord.x = "Longitude",
  coord.y = "Latitude",
  id.col = NULL,
  actel = FALSE
)

SimonDedman avatar Oct 16 '24 17:10 SimonDedman

Regarding this: would be especially good to have more info on id.col. Because I'm using a spatial object not csv, I have to use actel=FALSE, and thus specify everything else, which feels like a bit of a waste of the coding you've done in the backend.

Anyway, having done so, I've tried various things to solve a later warning that Colnames & rownames don't match due to Xs (colnames were 1 2 3 converted by R to X1 X2 X3 but then they don't match rownames which are 1 2 3):

id.col = Station.name,

Error: object 'Station.name' not found

id.col = spatial$Station.name,

Error: Please provide only one column name in 'id.col'

id.col = "Station.name",

Error in .rowNamesDF<-(x, value = value) : invalid 'row.names' length

spatial <- spatial |> dplyr::mutate(Station.name = stringr::str_replace_all(string = Station.name, pattern = " ", replacement = "_"))
id.col = "Station.name",

Error in .rowNamesDF<-(x, value = value) : invalid 'row.names' length

And finally, old faithful:

colnames(distances) <- spatial$Station.name
rownames(distances) <- spatial$Station.name

SimonDedman avatar Oct 22 '24 02:10 SimonDedman