我正在翻译在 Julia(用于主要代码 - https://rosettacode.org/wiki/Word_search#Julia)和 Python(用于创建 Grid 类 - https:// /rosettacode.org/wiki/Word_search#Python)。
我正在尝试将 Grid 的类定义从 Python(见下文)重写为 R:
class Grid:
def __init__(self):
self.num_attempts = 0
self.cells = [['' for _ in range(n_cols)] for _ in range(n_rows)]
self.solutions = []
以下是我将 Python 类转换为R6
类的尝试:
library("R6")
Grid <- R6Class("Grid",
public = list(
num_attempts = NULL,
cells = NULL,
solutions = NULL,
initialize = function(num_attempts = NA, cells = NA, solutions = NA) {
self$num_attempts <- 0
self$cells <- cells
self$solutions()
},
cells = function(val) {
for (val in seq_along(ncols)) {
for (val in seq_along(nrows))
{
result <- vector("character")
result
}
}
}
)
)
以下是我在 R 中收到的错误消息:
Error in R6Class("Grid", public = list(num_attempts = NULL, cells = NULL, :
All items in public, private, and active must have unique names.
请提供有关如何正确执行此翻译的建议。
谢谢你。