可以使用以下命令将Matlab
代码转换为R
代码
library(matconv)
mat2r(
inMat = "A.m"
, pathOutR = "A.R"
, funcConverters = NULL
, dataConverters = NULL
, verbose = 1
)
mat2r(
inMat = "B.m"
, pathOutR = "B.R"
, funcConverters = NULL
, dataConverters = NULL
, verbose = 1
)
然而,我正在寻找一些更高效的代码,如下所示:
library(purrr)
dir(path = ".", pattern = "*.m", full.names = FALSE) %>%
map(
.x = .
, .f = mat2r(
inMat = .
, pathOutR = paste0(., ".R")
, funcConverters = NULL
, dataConverters = NULL
, verbose = 1
)
)
这对我不起作用。请给我任何提示。
尝试以下操作:
dir(path = ".", pattern = "*.m") %>%
purrr::map(.f = ~mat2r(
inMat = .x
, pathOutR = sub('m$', "R", .x)
, funcConverters = NULL
, dataConverters = NULL
, verbose = 1
)
)