From for loop to lappy?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

From for loop to lappy?

Ek Esawi
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: From for loop to lappy?

R help mailing list-2
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" <[hidden email] on behalf of [hidden email]> 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
   
    ______________________________________________
    [hidden email] 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.
   

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: From for loop to lappy?

Ek Esawi
Thank you Don. It works
EK
On Mon, Oct 1, 2018 at 6:39 PM MacQueen, Don <[hidden email]> 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" <[hidden email] on behalf of [hidden email]> 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
>
>     ______________________________________________
>     [hidden email] 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.
>
>

______________________________________________
[hidden email] 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.