R only uploads blank excel file

I initially used this code to upload a password-protected Excel spreadsheet into R. It worked completely fine and I was able to read the file.

library("readxl")
library("dplyr")
library("excel.link")
library("tinytex")

new_path = paste0(tempdir(), "\\", "Bone_Dataset_7-13-2022.xlsx")
xl()[["Activeworkbook"]]$saveas(new_path, AccessMode=xl.constants$xlExclusive)
###
xl()[["Activesheet"]]$Unprotect(password = "Password")
bonedata = crc[a1]
xl.workbook.close()
unlink(new_path) # remove temporary Excel File

BoneData <- bonedata
BoneData

However, I am trying to knit my r.markdown file, and the code no longer seems to be working. It uploads a file with only 1 row and one column in it (there should be ~1500 rows).

Description:df [1 × 1]

|      |a              |
| -----| --------------|
| 1    | NA            |

What am I doing wrong here? Why did it work before, but not now??

Thank you so much!

Are you including all the library calls in the r.markdown document?

I think r.markdown runs in an empty environment.

Yes, I think so. Is including these sufficient or am I missing something?

library("readxl")
library("dplyr")
library("excel.link")
library("tinytex")

[/quote]

Looks okay to me. Does "excel.link" require some kind of manual input? I have never used it.

This looks like a lot of code, and a lot could go wrong. Can you test it more simply, and then slowly add more code?

library(readxl)
df <- data.frame(read_excel("C:/Users/Catherine/Desktop/R_files/Bone_Dataset_7-13-2022.xlsx"))
head(df,6)

Hi, thanks for the feedback. Unfortunately I can't use that code because the file is password protected.

It supposedly doesn't which is why I can't figure it out!

This topic was automatically closed 21 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.