Read a csv file with a specific format (see Details) and intepret it as network origin-destination data with possibly weighted edges.

read_network(x)

Arguments

x

character. Path of csv file

Value

Object of classes geonetwork and igraph.

Details

The file must be plain text with comma-separated columns and variable names in the first line. Field separators other than comma are also supported. In particular, semi-colon field separators and comma decimal separator. There must be either 6 or 7 columns in the same order and of the same types as follows:

  • origin character

  • destination character

  • lon_orig numeric (decimal degrees, WGS84)

  • lat_orig numeric (decimal degrees, WGS84)

  • lon_dest numeric (decimal degrees, WGS84)

  • lat_dest numeric (decimal degrees, WGS84)

  • volume Optional. directed flux in some consistent unit

Variable names can be different. If strings contain spaces they must be quoted. For this reason, quotes cannot be part of node names. E.g. the name Abangminko'O is invalid and will rise an error.

Each origin-destination must be specified only once. If you have multple animal shipments between the same origin and destination spread in several lines, you need to aggregate them into a single line.

Make sure coordinates are consistent. I.e. All nodes must have the same coordinates in all the lines where it appears as either source or destination.

Examples

d <- data.frame(from = "A", to = "B", fx = 0, fy = 0, tx = 1, ty = 1) tf <- tempfile() write.csv(d, tf, row.names = FALSE) read_network(tf)
#> Warning: All the links are unidirectional which seems implausible. #> Note that mapMCDA works only with directed networks. #> If you are sure that the network is directed, you can proceed.
#> IGRAPH d5801fa DN-- 2 1 -- #> + attr: name (v/c) #> + edge from d5801fa (vertex names): #> [1] A->B