Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of check_zero() in forceNetwork() and sankeyNetwork() #282

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions R/forceNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ forceNetwork <- function(Links,
opacityNoHover = 0,
clickAction = NULL)
{
# Check if data is zero indexed
check_zero(Links[, Source], Links[, Target])

# If tbl_df convert to plain data.frame
Links <- tbl_df_strip(Links)
Nodes <- tbl_df_strip(Nodes)
Expand All @@ -190,6 +187,14 @@ forceNetwork <- function(Links,
if (!is.data.frame(Nodes)) {
stop("Nodes must be a data frame class object.")
}

# if Source or Target are missing assume Source is the first
# column Target is the second column
if (missing(Source))
Source = 1
if (missing(Target))
Target = 2

if (missing(Value)) {
LinksDF <- data.frame(Links[, Source], Links[, Target])
names(LinksDF) <- c("source", "target")
Expand All @@ -207,6 +212,9 @@ forceNetwork <- function(Links,
names(NodesDF) <- c("name", "group")
nodesize = FALSE
}

# Check if data is zero indexed
check_zero(Links[, Source], Links[, Target])

LinksDF <- data.frame(LinksDF, colour = linkColour)
LinksDF$colour = as.character(LinksDF$colour)
Expand Down
7 changes: 4 additions & 3 deletions R/sankeyNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ sankeyNetwork <- function(Links, Nodes, Source, Target, Value,
fontFamily = NULL, nodeWidth = 15, nodePadding = 10, margin = NULL,
height = NULL, width = NULL, iterations = 32, sinksRight = TRUE)
{
# Check if data is zero indexed
check_zero(Links[, Source], Links[, Target])

# Hack for UI consistency. Think of improving.
colourScale <- as.character(colourScale)

Expand All @@ -95,6 +92,7 @@ sankeyNetwork <- function(Links, Nodes, Source, Target, Value,
if (!is.data.frame(Nodes)) {
stop("Nodes must be a data frame class object.")
}

# if Source or Target are missing assume Source is the first
# column Target is the second column
if (missing(Source))
Expand All @@ -110,6 +108,9 @@ sankeyNetwork <- function(Links, Nodes, Source, Target, Value,
Links[, Value])
names(LinksDF) <- c("source", "target", "value")
}

# Check if data is zero indexed
check_zero(Links[, Source], Links[, Target])

# if NodeID is missing assume NodeID is the first column
if (missing(NodeID))
Expand Down