Windows では、ファイル パスの長さに制限があります。
> write(1, paste0(paste(sample(letters, 150, TRUE), collapse = ''), '.txt'))
> write(1, paste0(paste(sample(letters, 250, TRUE), collapse = ''), '.txt'))
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
cannot open file 'qvxirpnlwkqfwlxhggkscxlwhhyblrwxfpikpsukrfqwhaqvsyhdpihnoknqmxgafvawxkuijqbmvgdjwwgeumfksmhtiqwvzwmjukmmmeesvcdpdbpimarxssnrngfxwjksqshjruralhtwdnfmdhzrcwcdrnwezdhwqyisbjikdhbbygtcoeechgwrewenewbrlexliiikdnwlclbzllaxcohacadxzztgmtnmppyxtxtbopxdokjnvx.txt': No such file or directory
このソースによると、260文字です
http://msdn.microsoft.com/en-us/library/aa365247.aspx#maxpath
> nchar(getwd())
[1] 23
> write(1, paste0(paste(sample(letters, 231, TRUE), collapse = ''), '.txt'))
> write(1, paste0(paste(sample(letters, 232, TRUE), collapse = ''), '.txt'))
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
cannot open file 'topylmudgfnrkdilqbklylwtbwrgwbwmamxzhwwzlxxslqeuhpywahoxqxpkckvmkfjccbsqncctlovcnxctkyvgunnbqcwyiliwpfkjibanpmtupsxfboxnjaadovtdpxeloqjnbqgvkcilwljfswzlrlqixmwqpoemcemhdizwwwbgqruhepyrskiklkbylzjhrcchbusohkrwyzgablvngqrqiardubcbziex.txt': No such file or directory
> getwd()
[1] "C:/Users/john/Documents"
> nchar(file.path(getwd(), paste0(paste(sample(letters, 231, TRUE), collapse = ''), '.txt')))
[1] 259
有効な解決策の 1 つは、長いディレクトリ パス用の仮想ドライブを作成することです。少し余裕を持たせる必要がありますhttps://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/subst.mspx?mfr=trueを参照
> system("subst x: C:/Users/john/Documents")
> write(1, paste0("x://", paste(sample(letters, 251, TRUE), collapse = ''), '.txt'))
仮想ドライブの操作が完了したら、次を使用して元に戻すことができます。
system("subst x: /D")