Hello, I have to create a function to read a maze from a .txt file.
My function is:
readMap <- function(path) {
con = file(path, "r")
while ( TRUE ) {
line = readLines(con, n = 1)
if ( length(line) == 0 ) {
break
}
print(line)
}
close(con)
}
To read my maze:
readMap("~path")
And it gives me the maze line by line as:
[1] "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[1] "s x x x"
[1] "xxxxx x x x x x x xxxx"
[1] "x x x x xxxxxx x"
[1] "x xxxxxxx x xxxxx x xxxx x"
[1] "x x x"
[1] "xxxxxxxxxxxxxxxxxxxxxxxxxx x"
[1] "xxx x x"
[1] "x x xxx x xxxxxxxxxxxxxxxxxx"
[1] "xxxxx xxx x x x"
[1] "x x xxx xxxxxxxx xxx"
[1] "x xxxxxx xxxx xx x x x x x"
[1] "x xx x x x x"
[1] "x xxxxxx xxxxxx xxxx x"
[1] "x x x x x xxx"
[1] "x x xxxx x xxxxxxxxxx xx x"
[1] "e xx x x x x"
[1] "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
How I can create the matrix with this output line by line? (x, spaces, e and s)