[R] From for loop to lappy?
Ek Esawi
e@@w|ek @end|ng |rom gm@||@com
Tue Oct 2 01:02:29 CEST 2018
Thank you Don. It works
EK
On Mon, Oct 1, 2018 at 6:39 PM MacQueen, Don <macqueen1 using llnl.gov> wrote:
>
> Try
>
> A <- lapply(file.names, function(fn) extract_tables(fn)
>
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> On 10/1/18, 3:32 PM, "R-help on behalf of Ek Esawi" <r-help-bounces using r-project.org on behalf of esawiek using gmail.com> wrote:
>
> Hi All—
>
> I am using Tabulizer to extract tables from PDF files. Tabulizer
> creates a list of matrices for each set of tables in each document.
> My code, below, works well. Then i thought i would use lapply instead
> of for loop since it is a little faster and more compact,
> but i kept getting an error message below.
>
> Any help is greatly appreciated
>
> EK
>
> install.packages("tabulizer")
> installed.packages("stringr")
> library(stringi)
> library(tabulizer)
> path = "C:/Users/name/Documents/TextMining/"
> file.names <- dir(path, pattern =".PDF")
>
> for(i in 1:length(file.names)){
> print(file.names[i])
> A[[i]] <- extract_tables(file.names[i])
> }
>
>
> lapply(file.names, function(i) A[[i]] <- extract_tables(file.names[i]))
>
> Error in normalizePath(path.expand(path), winslash, mustWork) :
> path[1]="NA": The system cannot find the file specified
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
More information about the R-help
mailing list