% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/multilayer_to_csv.R
\name{multilayer_to_csv}
\alias{multilayer_to_csv}
\title{Export a multilayer network to CSV files}
\usage{
multilayer_to_csv(
  multilayer,
  dir,
  prefix = "network",
  bipartite = FALSE,
  setA_type = NULL,
  directed = NULL
)
}
\arguments{
\item{multilayer}{A multilayer object (created by
\code{create_multilayer_network} or \code{load_emln}).}

\item{dir}{Directory to write the CSV files to. Created if it does not
already exist.}

\item{prefix}{Character. File name prefix. Defaults to \code{"network"}.
Three files are always written:
\code{<prefix>_edges.csv}, \code{<prefix>_layers.csv},
\code{<prefix>_nodes.csv}.
A fourth file \code{<prefix>_state_nodes.csv} is written when the
multilayer object contains per-(layer, node) attributes beyond
\code{layer_name} and \code{node_name} (e.g. abundance,
module).}

\item{bipartite}{Logical. Whether the network is bipartite. Defaults to
\code{FALSE}. When \code{TRUE}, the nodes table must contain a
\code{node_type} (or legacy \code{node_group}) column with exactly two
distinct values across the network, and a \code{bipartite} column is
written to the layers CSV.}

\item{setA_type}{Optional character. The \code{node_type} value to render
as Set A (top row) in MiRA's bipartite layout. By ecological convention
this is the higher trophic level (e.g. \code{"pollinator"},
\code{"parasite"}, \code{"disperser"}). Only used when
\code{bipartite = TRUE}; written as a \code{setA_type} column in the
layers CSV. If \code{NULL} (default), MiRA falls back to alphabetical
ordering of the two types.}

\item{directed}{Logical or NULL. Whether the network is directed. If NULL
(default), auto-detected by checking intralayer edge symmetry.}
}
\value{
Invisibly returns a named character vector of file paths written
  (\code{edges}, \code{layers}, \code{nodes}, and optionally
  \code{state_nodes}).
}
\description{
Writes an EMLN \code{multilayer} object as a set of CSV files consumed
by MiRA's CSV importer. Three files are always written; a fourth
(\code{<prefix>_state_nodes.csv}) is added when per-(layer, node)
attributes are present.
}
\details{
The CSV files follow the schema accepted by MiRA's CSV importer:
\itemize{
  \item \strong{edges}: \code{layer_from, node_from, layer_to, node_to,
    weight} (+ any extra link attributes).
  \item \strong{layers}: \code{layer_id, layer_name} (+ \code{latitude,
    longitude, bipartite} and any extra layer attributes).
  \item \strong{nodes}: \code{node_name} (+ \code{node_type} and any extra
    physical node attributes, same across all layers).
    \code{node_group} is renamed to \code{node_type}.
  \item \strong{state_nodes} (written only when extra per-(layer, node)
    attributes exist): \code{layer_name, node_name} + extra columns.
    Use this when the same node has different attribute values in
    different layers (e.g. abundance, module membership).
}
The \code{directed} flag is not written to the CSV files; it is a property
you specify in MiRA's CSV import dialog at load time.
}
\note{
MiRA (Multilayer Interactive Rendering Application) is a browser-based
interactive visualization tool for multilayer networks, available at
\url{https://mira.ecomplab.com/}.

If you use MiRA in published research, please cite:

Nehoray SM, Bloch Y, Pilosof S (2026). Interactively visualizing biological
multilayer networks using MiRA. \emph{arXiv}:2605.09597 [cs.SI].
\doi{doi:10.48550/arXiv.2605.09597}

Feedback and bug reports:
\url{https://github.com/Ecological-Complexity-Lab/MiRA/issues}.
}
\examples{
\donttest{
net <- load_emln(14)
multilayer_to_csv(net, dir = "tests/out/", prefix = "kefi", bipartite = TRUE)
}
}
\seealso{
\code{\link{multilayer_to_json}}, \code{\link{plot_multilayer}}
}
