Skip to content
Open
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
6 changes: 4 additions & 2 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,8 @@ graph.data.frame <- function(d, directed = TRUE, vertices = NULL) {
#' "Esmeralda"
#' ),
#' age = c(48, 33, 45, 34, 21),
#' gender = c("F", "M", "F", "M", "F")
#' gender = c("F", "M", "F", "M", "F"),
#' stringsAsFactors = FALSE
#' )
#' relations <- data.frame(
#' from = c(
Expand All @@ -1953,7 +1954,8 @@ graph.data.frame <- function(d, directed = TRUE, vertices = NULL) {
#' ),
#' to = c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
#' same.dept = c(FALSE, FALSE, TRUE, FALSE, FALSE, TRUE),
#' friendship = c(4, 5, 5, 2, 1, 1), advice = c(4, 5, 5, 4, 2, 3)
#' friendship = c(4, 5, 5, 2, 1, 1), advice = c(4, 5, 5, 4, 2, 3),
#' stringsAsFactors = FALSE
#' )
#' g <- graph_from_data_frame(relations, directed = TRUE, vertices = actors)
#' print(g, e = TRUE, v = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/glet.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ graphlets.candidate.basis <- function(graph, weights = NULL) {
#' gl <- graphlets(g, niter = 1000)
#'
#' ## Plot graphlets
#' for (i in 1:length(gl$cliques)) {
#' for (i in seq_along(gl$cliques)) {
#' sel <- gl$cliques[[i]]
#' V(g)$color <- "white"
#' V(g)[sel]$color <- "#E495A5"
Expand Down
2 changes: 1 addition & 1 deletion R/operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ apply_attr_combiner <- function(comb, vals, type) {
x <- x[!is.na(x)]
apply_one_combiner(comb, x)
})
if (all(vapply(out, length, integer(1)) == 1L)) {
if (all(lengths(out) == 1L)) {
unlist(out)
} else {
out
Expand Down
7 changes: 5 additions & 2 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@
}))
) {
## create a table
tab <- data.frame(v = paste(sep = "", "[", ind, "]"), row.names = "v")
tab <- data.frame(
v = paste(sep = "", "[", ind, "]"),
row.names = "v",
stringsAsFactors = FALSE
)
for (i in list) {
tab[i] <- vertex_attr(x, i, ind)
}
Expand Down Expand Up @@ -373,7 +377,6 @@ print_edge_detail <- function(graph, edges) {
if (!is.null(x)) {
arrow <- c("--", "->")[is_directed(x) + 1]

# jarl-ignore unused_object: then assigned to with <<-
can_max <- NA
el <- NA

Expand Down
6 changes: 4 additions & 2 deletions man/graph_from_data_frame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/graphlet_basis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions tests/testthat/test-attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ test_that("bracketing works (not changing attribute of similar graphs)", {
g <- make_graph(c(1, 2, 1, 3, 3, 4))

g <- set_vertex_attr(g, name = "weight", value = 1:vcount(g))
# jarl-ignore unused_object: test design
graph2 <- set_vertex_attr(g, name = "weight", value = rep(1, vcount(g)))
expect_equal(vertex_attr(g, name = "weight"), 1:4)

g <- set_edge_attr(g, name = "weight", value = 1:ecount(g))
# jarl-ignore unused_object: test design
graph2 <- set_edge_attr(g, name = "weight", value = rep(1, ecount(g)))
expect_equal(edge_attr(g, name = "weight"), 1:3)

g <- set_graph_attr(g, name = "name", "foo")
# jarl-ignore unused_object: test design
graph2 <- set_graph_attr(g, name = "name", "foobar")
expect_equal(graph_attr(g, name = "name"), "foo")
})
Expand All @@ -41,7 +38,6 @@ test_that("bracketing works with a function (not changing attribute of similar g
graph2
}

# jarl-ignore unused_object: test design
g2 <- copy_test(g)
expect_equal(vertex_attr(g, name = "weight"), 1:4)
expect_equal(edge_attr(g, name = "weight"), 1:3)
Expand All @@ -61,7 +57,6 @@ test_that("bracketing works with shortcuts (not changing attribute of similar gr
graph$name <- "foobar"
}

# jarl-ignore unused_object: test design
g_copy <- copy_test(g)
expect_equal(vertex_attr(g, name = "weight"), 1:4)
expect_equal(edge_attr(g, name = "weight"), 1:3)
Expand Down
18 changes: 14 additions & 4 deletions tests/testthat/test-conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,8 @@ test_that("graph_from_data_frame works with factors", {
actors <- data.frame(
name = c("Alice", "Bob", "Cecil", "David", "Esmeralda"),
age = c(48, 33, 45, 34, 21),
gender = factor(c("F", "M", "F", "M", "F"))
gender = factor(c("F", "M", "F", "M", "F")),
stringsAsFactors = FALSE
)
relations <- data.frame(
from = c(
Expand All @@ -915,7 +916,8 @@ test_that("graph_from_data_frame works with factors", {
to = c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
same.dept = c(FALSE, FALSE, TRUE, FALSE, FALSE, TRUE),
friendship = c(4, 5, 5, 2, 1, 1),
advice = c(4, 5, 5, 4, 2, 3)
advice = c(4, 5, 5, 4, 2, 3),
stringsAsFactors = FALSE
)
g <- graph_from_data_frame(relations, directed = TRUE, vertices = actors)

Expand Down Expand Up @@ -1188,8 +1190,16 @@ test_that("graph_from_adj_list() covers duplicate by name and recovers positiona
})

test_that("graph_from_data_frame() recovers positional vertices with a deprecation", {
edges <- data.frame(from = c("a", "b"), to = c("b", "c"))
verts <- data.frame(name = c("a", "b", "c"), size = 1:3)
edges <- data.frame(
from = c("a", "b"),
to = c("b", "c"),
stringsAsFactors = FALSE
)
verts <- data.frame(
name = c("a", "b", "c"),
size = 1:3,
stringsAsFactors = FALSE
)

lifecycle::expect_deprecated(
res <- graph_from_data_frame(edges, TRUE, verts)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-glet.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ test_that("Graphlets filtering works", {
df <- data.frame(
from = c("A", "A", "B", "B", "B", "C", "C", "D"),
to = c("B", "C", "C", "D", "E", "D", "E", "E"),
weight = c(8, 8, 8, 5, 5, 5, 5, 5)
weight = c(8, 8, 8, 5, 5, 5, 5, 5),
stringsAsFactors = FALSE
)

g <- graph_from_data_frame(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ test_that("get_edge_id() errors correctly for wrong vp", {
expect_error(get_edge_ids(g, NA))

V(g)$name <- letters[1:3]
df <- data.frame(from = c("a", "b"), to = c(1, 2))
df <- data.frame(from = c("a", "b"), to = c(1, 2), stringsAsFactors = FALSE)
expect_snapshot_igraph_error({
get_edge_ids(g, df)
})
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-iterators.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ test_that("vs/es refers to the original graph", {
vs <- V(ring1)
es <- E(ring1)

# jarl-ignore unused_object: test design
ring1 <- ring1 + 4

expect_identical(get_vs_graph(vs), ring2)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-migration-fixture.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# jarl-ignore-file missing_argument: this is the test's point
# Tests for the in-place argument-migration generator (tools/generate-migrations.R)
# via the fixture `migration_fixture()` (R/migration-fixture.R). Old signature
# f(graph, n, weight, kind, directed); new f(graph, n, ..., weights, type,
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-plot.shapes.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# jarl-ignore-file implicit_assignment: just the way it works
test_that("shapes() lists all available shapes", {
all_shapes <- shapes()
expect_type(all_shapes, "character")
Expand Down
14 changes: 9 additions & 5 deletions tests/testthat/test-sparsedf.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("sdf works", {
sdf <- sdf(id = 1:10, color = "black")
expect_equal(
as.data.frame(sdf),
data.frame(id = 1:10, color = "black")
data.frame(id = 1:10, color = "black", stringsAsFactors = FALSE)
)

## access
Expand All @@ -26,28 +26,32 @@ test_that("sdf works", {
sdf2[5, "id"] <- 100
expect_equal(
as.data.frame(sdf2),
data.frame(id = c(1:4, 100, 6:10), color = "black")
data.frame(
id = c(1:4, 100, 6:10),
color = "black",
stringsAsFactors = FALSE
)
)

sdf2 <- sdf
sdf2[, "id"] <- 0
expect_equal(
as.data.frame(sdf2),
data.frame(id = rep(0, 10), color = "black")
data.frame(id = rep(0, 10), color = "black", stringsAsFactors = FALSE)
)

sdf2 <- sdf
sdf2[2:10, "id"] <- 1
expect_equal(
as.data.frame(sdf2),
data.frame(id = rep(1, 10), color = "black")
data.frame(id = rep(1, 10), color = "black", stringsAsFactors = FALSE)
)

sdf2 <- sdf
sdf2[, "color"] <- "white"
expect_equal(
as.data.frame(sdf2),
data.frame(id = 1:10, color = "white")
data.frame(id = 1:10, color = "white", stringsAsFactors = FALSE)
)

sdf2 <- sdf
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-structural-properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ test_that("BFS callback does not blow up when an invalid value is returned", {
})

test_that("BFS callback does not blow up when an error is raised within the callback", {
# jarl-ignore unreachable_code: <reason>
# jarl-ignore unreachable_code: test design
callback <- function(graph, data, extra) {
cli::cli_abort("test")
FALSE
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-weakref.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ test_that("weak reference finalizer is called", {
value <- "foobar"
hello <- ""
fin <- function(env) hello <<- "world"
# jarl-ignore unused_object: test design
vs <- make_weak_ref(key = g, value = value, finalizer = fin)

rm(g)
gc()

Expand Down
Loading