Question on file paths, lists,

when I used this code to prepend a path to a list of images

indexok <- lapply(indexok,gsub(" ","",paste("~/datasciencelocal/TaiChi/pngs",indexok)))

it gave an error : ~/datasciencelocal/TaiChi/pngs/NULL
when i gave in with indexok[1] is gave instead of NULL the correct filename: ~/datasciencelocal/TaiChi/pngs/1.png
Is it normal? what did i wrong?
Kind regards, thx for helping me,

best guess :

newindexok <- lapply(indexok,function(x_)file.path("~/datasciencelocal/TaiChi/pngs",x_))
1 Like

srru i was to early to early by saying it works
i tried it out in my program but still get this error
Error in tesseract::ocr(newindexok[i]) :
Argument 'image' must be file-path, url or raw vector

lapply gives a list; you can unlist it to be , in this case, a character vector with unlist()

newindexok_list <- lapply(indexok,function(x_)file.path("~/datasciencelocal/TaiChi/pngs",x_))
newindexok <- unlist(newindexok_list)

either that or use sapply instead of lapply


thx now i tested it out it works realy fine now.
I used following command
indexok <- sapply(indexok,function(x_)file.path("~/datasciencelocal/TaiChi/pngs",x_))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.