Error in file(con, "rb") : cannot open the connection

I'm trying to read a csv file and I keep getting this message. I'm very new to R. I think I've set the right working directory, and it seems like it's an issue with file permissions. As far as I can tell I have write permission for this file. Not sure how to resolve this issue.

library(ggplot2)
library(tidyverse)
library(data.table)
#> 
#> Attaching package: 'data.table'
#> The following objects are masked from 'package:dplyr':
#> 
#>     between, first, last
#> The following object is masked from 'package:purrr':
#> 
#>     transpose
setwd("C:\\Users\\Lee\\Documents\\R\\housing")
housing_census_2016 <- read_csv("C:\\Users\\Lee\\Documents\\R\\housing\\housing_census_2016")
#> Warning in file(con, "rb"): cannot open file 'C:/Users/Lee/Documents/R/housing/
#> housing_census_2016': Permission denied
#> Error in file(con, "rb"): cannot open the connection

Does the file name not have an extension like .csv? The command would then be

housing_census_2016 <- read_csv("C:\\Users\\Lee\\Documents\\R\\housing\\housing_census_2016.csv")

I think you get the permission denied message if you try to use read.csv on a directory.

1 Like

Thank you! This was the issue

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.