how to obtain the character vector from dir_ls of fs package?

Hi! I would like to know how to get the "character" vector of the output of dir_ls from fs package.

nomb <- dir_ls(glob = "*.xlsx")

nomb %>% class()

The result of the last part is "fs_path" "character". Until this time, I haven't found the way of how to extract the latest part. Please any comment and help with this will be highly appreciate.
Thank you.
Regards

You can use as.character

library(fs)
library(magrittr)

dir_ls() %>% class()
#> [1] "fs_path"   "character"
dir_ls() %>% as.character() %>% class()
#> [1] "character"

unname(dir_ls() == as.character(dir_ls()))
#> [1] TRUE TRUE TRUE

Created on 2020-01-05 by the reprex package (v0.2.1)

The fs_path is just an additional class added to the character vector by the fs package. It is likely used for s3 methods within the package itself. If you pass the nomb object to any function that takes a character vector then it should still work the same way as it still inherits the character class.

3 Likes

Thanks a lot for your support. It fixed what I wanted to do.
Regards

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