'Issues on importing multiple files

I am new to R. Currently I have spent hours on Youtube videos looking to import a folder of CSV files for my data analytics project. The following are my codes:

enter code here



 library(tidyverse) 
 library(fs)  
 library(purrr)
     
 directory_that_holds_files <- "/Users/users/Desktop/capstone.project/nasdaq_index_csv"
    
  nasdaq_indexes <- directory_that_holds_files%>%
     dir_ls()%>%
         map( 
            .f = function(path) {
               read_csv(
                   path, 
                   col_types = cols(
                     Date = col_double(),
                     Close/Last = col_double(),
                     Open = col_double(),
                     High = col_double(),
                     Low = col_double() 
                     )
                 )
           }
    )

Here's what happens when I run these codes:

library(tidyverse)
library(fs)
library(purrr)

directory_that_holds_files <- "/Users/users/Desktop/capstone.project/nasdaq_index_csv"

  nasdaq_indexes <- directory_that_holds_files%>%
     dir_ls()%>%
         map( 
            .f = function(path) {
               read_csv(
                   path, 
                   col_types = cols(
                     Date = col_double(),
                     Close/Last = col_double(),
 **Error: unexpected '=' in:**
               **Date = col_double(),
               Close/Last ="**
               Open = col_double(),
**Error: unexpected ',' in "                Open = col_double(),"**
              High = col_double(),
**Error: unexpected ',' in "                High = col_double(),"**
              Low = col_double() 
              )
**Error: unexpected ')' in "                 )"**
           )
**Error: unexpected ')' in "              )"**
      }
**Error: unexpected '}' in "        }"**
     )
**Error: unexpected ')' in "    )"**

I have checked the brackets multiple times and I am pretty sure that the brackets are matched, yet the error messages appear. Extremely grateful if anyone could provide some insights on improving my codes.

My R studio version is 4.1.3

Update: Here is the output of problems()

r


Solution 1:[1]

I believe your issue is with this line:

...
Close/Last = col_double(),
...

Convert this to

`Close/Last` = col_double(),

And that should fix your issue. This is because R doesn't recognize "/" as a valid character for naming variables. You need to tell R that the whole term is a variable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick Camarda