READR-Error: Cannot open file for writing

I keep getting this error when trying to make a .csv using 'readr' package:

Error: Cannot open file for writing:

  • 'data/bbd_1.csv'

please help. what am i doing wrong??


title: "rsm1"
output: html_document
date: "2023-01-14"

library(rsm)
## Warning: package 'rsm' was built under R version 4.2.1
bb_design_1 <- bbd(
  k  = 4,            # Number of factors,
  n0 = 3,            # Number of center points,
  block = FALSE,     # Consider blocks or not in the design 
  randomize = FALSE  # Randomize or not the order experiments
)

head(as.data.frame(bb_design_1))
##   run.order std.order x1 x2 x3 x4
## 1         1         1 -1 -1  0  0
## 2         2         2  1 -1  0  0
## 3         3         3 -1  1  0  0
## 4         4         4  1  1  0  0
## 5         5         5  0  0 -1 -1
## 6         6         6  0  0  1 -1

readr::write_csv(bb_design_1, file = "data/bbd_1.csv")

For this to work there must exist a directory named data in your current working directory. You can check from the Console pane with dir() or look in the Files pane.

i thought it would write the directory and call it "data." i still cant get it to work

Create a new folder under your project directory called data first.

1 Like

YOU ARE THE FREAKING MAN! THANK YOU!!! im trying to teach myself...

1 Like

Consider using RStudio projects (File | New Project) and create the data folder there. Then

install.packages("here")

then, wherever you are working in the project you can refer to your files in that folder without worrying how many subdirectories up, over and down they might be.

read.csv(here::here("data/your.csv")

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.