Putting it together

We’ve made a function, and iterated through that function. So let’s go one step further and make a function with the iteration built in:

read_patents <- function(file_dir){
  patents <- do.call("rbind", 
                     lapply(list.files(file_dir, full.names = T),
                            function(x){
                  df <- read.csv(x)
                  df$App_Date <- ymd(as.character(df$App_Date))
                  df$Issue_Date <- ymd(as.character(df$Issue_Date))
                  return(df)
                  }))
  return(patents)
}

Now all we have to do is use this singular function with the director of all files to read in and combine the patents:

patents <- read_patents("~/Box/d-rug/data/")
## Warning: 1 failed to parse.

## Warning: 1 failed to parse.

## Warning: 1 failed to parse.
head(patents)
##         WKU                          Title   App_Date Issue_Date
## 1 D02428814                 Diver s helmet 1975-09-08 1977-01-04
## 2 D02428822 Combined brush and ice scraper 1976-04-21 1977-01-04
## 3 D02428830                     Toothbrush 1975-09-17 1977-01-04
## 4 D02428849        Stand for potted plants 1976-01-07 1977-01-04
## 5 D02428857                          Chair 1975-08-18 1977-01-04
## 6 D02428865        Seat or similar article 1975-06-02 1977-01-04
##                 Inventor                        Assignee   ICL_Class
## 1       Richard F. Jones          General Aquadyne, Inc.       D0203
## 2      Otto W. Schneider            Erwin Weller Company D0401;D0705
## 3     Thomas J. De Marco                                 D0402;D2402
## 4             Peter Diaz Lawrence Peska Associates, Inc.       D0604
## 5 Lee Harold Fister, Jr.                                       D0601
## 6       Taylor M. Potter                                       D0601
##                                       References
## 1                                3845768;3943571
## 2        D184943;D228585;2856621;2981964;3017649
## 3                 D56858;1209789;2677843;3677264
## 4                        D137106;D165328;1406893
## 5                                               
## 6 D49656;D219583;D227834;D234171;D237923;3563599
##                                                                                                          Claims
## 1                                                         The ornamental design for a diver s helmet, as shown.
## 2 The ornamental design for a combined brush and ice scraper, or the like,substantially as shown and described.
## 3                                  The ornamental design for a toothbrush, substantially as shown anddescribed.
## 4                                   The ornamental design for a stand for potted plants, substantially asshown.
## 5                                                                  The ornamental design for a chair, as shown.
## 6                                                The ornamental design for a seat or similar article, as shown.