2021年3月7日星期日

R - Getting "Error "..." does not exist in current working directory, but it's clearly there

I'm trying to write a loop in R. The first part of my code works fine, which is to concatenate a URL and a value containing three years (1999-2001).

url <- 'https://www.baseball-almanac.com/players/baseball_births.php?order=LastName,%20FirstName&y='  birth_yrs <- as.character(1999:2001)    for(i in birth_yrs) {     nam <- paste("year", i, sep = ".")    assign(nam, i)    nam2<-paste(url, i ,sep = "")    assign(nam,paste(url, i ,sep = ""))  }  

This gives me the following values in my Global Environment:

View of my Global Environment What I would like to do now is to use the read_html() function in the from the xml2 package in a loop to save the html page. My code is the following:

for(i in birth_yrs) {     nam3 <- paste("baseball", i, sep = ".")    assign(nam3,read_html(paste("year",i,sep = "")))  }  

Running this code gives me the following error message:

Error: 'year1999' does not exist in current working directory ('C:/Users/.....').

When I run the code:

test<-read_html(year.1999)  

It works perfect with no issues: The file code worked fine

Any suggestions would be greatly appreciated.

Thank you.

https://stackoverflow.com/questions/66521857/r-getting-error-does-not-exist-in-current-working-directory-but-its-c March 08, 2021 at 05:54AM

没有评论:

发表评论