
Recommend direct usage of data.frame()
to create a data.frame from a list
Source: R/list2df_linter.R
list2df_linter.Rd
list2DF()
is the preferred way to turn a list of columns into a data.frame.
Note that it doesn't support recycling; if that's required, use data.frame()
.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "do.call(cbind.data.frame, x)",
linters = list2df_linter()
)
#> <text>:1:1: warning: [list2df_linter] Use `list2DF(lst)` instead of `do.call(cbind.data.frame, lst)`. If recycling is required, use `data.frame(lst)`.
#> do.call(cbind.data.frame, x)
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
lint(
text = "do.call('cbind.data.frame', x)",
linters = list2df_linter()
)
#> <text>:1:1: warning: [list2df_linter] Use `list2DF(lst)` instead of `do.call(cbind.data.frame, lst)`. If recycling is required, use `data.frame(lst)`.
#> do.call('cbind.data.frame', x)
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lint(
text = "do.call(cbind.data.frame, list(a = 1, b = 1:10))",
linters = list2df_linter()
)
#> <text>:1:1: warning: [list2df_linter] Use `list2DF(lst)` instead of `do.call(cbind.data.frame, lst)`. If recycling is required, use `data.frame(lst)`.
#> do.call(cbind.data.frame, list(a = 1, b = 1:10))
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# okay
lint(
text = "list2df(x)",
linters = list2df_linter()
)
#> ℹ No lints found.
lint(
text = "data.frame(list(a = 1, b = 1:10))",
linters = list2df_linter()
)
#> ℹ No lints found.