rstudio / pins-r

Pin, discover, and share resources
https://pins.rstudio.com
Other
316 stars 62 forks source link

Errors using board_folder() with VSCode+Python+radian #510

Closed hongooi73 closed 3 years ago

hongooi73 commented 3 years ago

I'm not sure if this is purely a pins bug, or an unexpected interaction with my IDE setup. I'm trying to create a simple local board:

f <- "~/misc/pins/tempboard3"
dir.create(f, recursive=TRUE)
b <- board_folder(f)
b %>% pin_write(mtcars, "mtcars")

This results in

Guessing `type = 'rds'`
Creating new version '20210912T095121Z-0fc2e'
Error in file(file, "w", encoding = fileEncoding) : 
  cannot open the connection
In addition: Warning message:
In file(file, "w", encoding = fileEncoding) :
  cannot open file 'C:\Users\hongo\Documents/misc/pins/tempboard3/mtcars/20210912T095121Z-0fc2e/data.txt': No such file or directory

Indeed, I can see that the 'tempboard3' folder (I previously tried tempboard and tempboard2, changing the names each time to ensure I wasn't picking up a stale cache) is empty. However, there is apparently something in b:

Pin board <pins_board_folder> 
Path: '~/misc/pins/tempboard3'
Cache size: 0
Pins [1]: 'mtcars'

I went looking for the cache folder, and eventually found it in: C:\Users\hongo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\Local\pins

which is a location owned by the Python app from the Microsoft store. Python is involved because I use radian, which is a Python-powered R interpreter. I'm not sure why it's there, I'd have expected the cache to sit under an R-specific location. In any case, deleting that folder and trying again still gave the above error.

hongooi73 commented 3 years ago

sessionInfo():

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] pins_0.99.9000 testthat_3.0.1 devtools_2.3.2 usethis_2.0.0

loaded via a namespace (and not attached):
 [1] zip_2.1.1           pillar_1.4.4        compiler_4.0.2      prettyunits_1.1.1  
 [5] remotes_2.2.0       tools_4.0.2         digest_0.6.27       pkgbuild_1.2.0     
 [9] pkgload_1.1.0       bit_1.1-15.2        tibble_3.0.1        jsonlite_1.7.2     
[13] memoise_1.1.0       lifecycle_0.2.0     pkgconfig_2.0.3     rlang_0.4.10       
[17] cli_2.2.0           rstudioapi_0.11     filelock_1.0.2      yaml_2.2.1
[21] withr_2.4.0         httr_1.4.2          rappdirs_0.3.1      askpass_1.1        
[25] desc_1.2.0          fs_1.5.0            vctrs_0.3.6         rprojroot_1.3-2        
[29] bit64_0.9-7         tidyselect_1.1.0    glue_1.4.1          R6_2.4.1
[33] processx_3.4.5.9001 fansi_0.4.1         sessioninfo_1.1.1   whisker_0.4
[37] callr_3.5.1         purrr_0.3.4         magrittr_1.5        backports_1.1.8        
[41] ps_1.6.0            ellipsis_0.3.1      assertthat_0.2.1    mime_0.9
[45] arrow_5.0.0         openssl_1.4.3       crayon_1.3.4
hongooi73 commented 3 years ago

Environment variables. The only place Python shows up is in the PYTHONUSERBASE var.

ALLUSERSPROFILE           C:\ProgramData
APPDATA                   C:\Users\hongo\AppData\Roaming
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL
                          true
AZURITE_ACCOUNTS          account1:key1
ChocolateyInstall         C:\ProgramData\chocolatey
ChocolateyLastPathUpdate
                          132187821501971029
CHROME_CRASHPAD_PIPE_NAME
                          \\.\pipe\crashpad_8724_OTKNINGJQGANAMON
CMDER_ROOT                NA
COLORTERM                 truecolor
CommonProgramFiles        C:\Program Files\Common Files
CommonProgramFiles(x86)   C:\Program Files (x86)\Common Files
CommonProgramW6432        C:\Program Files\Common Files
COMPUTERNAME              LAPTOP-P18OIHUP
ComSpec                   C:\WINDOWS\system32\cmd.exe
configsetroot             C:\WINDOWS\ConfigSetRoot
DriverData                C:\Windows\System32\Drivers\DriverData
GIT_ASKPASS               c:\Program Files\Microsoft VS
                          Code\resources\app\extensions\git\dist\askpass.sh
HOME                      C:\Users\hongo\Documents
HOMEDRIVE                 C:
HOMEPATH                  \Users\hongo
LANG                      en_GB.UTF-8
LOCALAPPDATA              C:\Users\hongo\AppData\Local
LOGONSERVER               \\LAPTOP-P18OIHUP
MSYS2_ENV_CONV_EXCL       R_ARCH
NUMBER_OF_PROCESSORS      12
OneDrive                  C:\Users\hongo\OneDrive
OneDriveConsumer          C:\Users\hongo\OneDrive
ORIGINAL_XDG_CURRENT_DESKTOP
                          undefined
OS                        Windows_NT
PATH                      C:\Program Files\R\R-4.0.2\bin\x64;C:\Program Files
                          (x86)\Microsoft
                          SDKs\Azure\CLI2\wbin;C:\Rtools\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program
                          Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program
                          Files (x86)\NVIDIA
                          Corporation\PhysX\Common;C:\Program
                          Files\dotnet\;C:\Program Files
                          (x86)\dotnet\;C:\ProgramData\chocolatey\bin;C:\Program        
                          Files\MiKTeX
                          2.9\miktex\bin\x64\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program
                          Files\Intel\WiFi\bin\;C:\Program Files\Common
                          Files\Intel\WirelessCommon\;C:\Program
                          Files\Microsoft VS Code\bin;C:\Program
                          Files\PowerShell\7\;C:\Program
                          Files\nodejs\;C:\Program Files\Git\cmd;C:\Program
                          Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\hongo\AppData\Local\Microsoft\WindowsApps;C:\Users\hongo\AppData\Local\GitHubDesktop\bin;C:\Users\hongo\AppData\Local\Pandoc\;C:\Users\hongo\AppData\Local\Microsoft\WindowsApps;c:\tools;C:\Users\hongo\AppData\Roaming\npm
PATHEXT                   .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
POWERSHELL_DISTRIBUTION_CHANNEL
                          MSI:Windows 10 Pro
PROCESSOR_ARCHITECTURE    AMD64
PROCESSOR_IDENTIFIER      Intel64 Family 6 Model 158 Stepping 10,
                          GenuineIntel
PROCESSOR_LEVEL           6
PROCESSOR_REVISION        9e0a
ProgramData               C:\ProgramData
ProgramFiles              C:\Program Files
ProgramFiles(x86)         C:\Program Files (x86)
ProgramW6432              C:\Program Files
PSModulePath              C:\Program
                          Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC                    C:\Users\Public
PYTHONUSERBASE            C:\Users\hongo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages
R_ARCH                    /x64
R_COMPILED_BY             gcc 8.3.0
R_DOC_DIR                 C:\Program Files\R\R-4.0.2\doc
R_HOME                    C:/Program Files/R/R-4.0.2
R_INCLUDE_DIR             C:\Program Files\R\R-4.0.2\include
R_LIBS_USER               C:\Users\hongo\Documents/R/win-library/4.0
R_SHARE_DIR               C:\Program Files\R\R-4.0.2\share
R_USER                    C:\Users\hongo\Documents
RADIAN_VERSION            0.5.11
RCHITECT_REGISTER_SIGNAL_HANDLERS
                          1
RCHITECT_RETICULATE_CONFIG
                          0
RTOOLS40_HOME             C:\rtools40
SESSIONNAME               Console
SSH_ASKPASS               C:/Rlib/askpass/win-askpass64.exe
SystemDrive               C:
SystemRoot                C:\WINDOWS
TEMP                      C:\Users\hongo\AppData\Local\Temp
TERM_PROGRAM              vscode
TERM_PROGRAM_VERSION      1.60.0
TMP                       C:\Users\hongo\AppData\Local\Temp
TMPDIR                    c:\Rtmp
USERDOMAIN                LAPTOP-P18OIHUP
USERDOMAIN_ROAMINGPROFILE
                          LAPTOP-P18OIHUP
USERNAME                  hongo
USERPROFILE               C:\Users\hongo
VSCODE_GIT_ASKPASS_MAIN   c:\Program Files\Microsoft VS
                          Code\resources\app\extensions\git\dist\askpass-main.js        
VSCODE_GIT_ASKPASS_NODE   C:\Program Files\Microsoft VS Code\Code.exe
VSCODE_GIT_IPC_HANDLE     \\.\pipe\vscode-git-f7781b9925-sock
VSCODE_INIT_R             c:\Users\hongo\.vscode\extensions\ikuyadeu.r-2.2.0\R\init.R   
VSCODE_WATCHER_DIR        C:\Users\hongo\.vscode-R
windir                    C:\WINDOWS
hongooi73 commented 3 years ago

Traceback:

15: file(file, "w", encoding = fileEncoding)
14: yaml::write_yaml(x, path) at utils.R#72
13: write_yaml(x, path) at meta.R#30
12: write_meta(metadata, version_dir) at board_folder.R#79
11: pin_store.pins_board_folder(board, name, path, meta, versioned = versioned,
        x = x, ...) at pin-store-fetch.R#25
10: pin_store(board, name, path, meta, versioned = versioned, x = x,
        ...) at pin-read-write.R#97
9: pin_write(., mtcars, "mtcars")
8: function_list[[k]](value)
7: withVisible(function_list[[k]](value))
6: freduce(value, `_function_list`)
5: `_fseq`(`_lhs`)
4: eval(quote(`_fseq`(`_lhs`)), env, env)
3: eval(quote(`_fseq`(`_lhs`)), env, env)
2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1: b %>% pin_write(mtcars, "mtcars")
hongooi73 commented 3 years ago

The error also happens when I run the code from rgui.exe, so I'm guessing it's not a radian/Python issue.

hadley commented 3 years ago

You can find the cache location withrappdirs::user_cache_dir("pins"), but that shouldn't be involved here because local boards don't use a cache.

Can you try it without the dir.create()? pins will automatically create the subdirectories for you.

Having two types of slashes in 'C:\Users\hongo\Documents/misc/pins/tempboard3/mtcars/20210912T095121Z-0fc2e/data.txt' is a little worrying but I suspect that comes from something like normalizePath("~/misc/pins/tempboard3").

hongooi73 commented 3 years ago

Well, what do you know:

r$> rappdirs::user_cache_dir("pins")
[1] "C:\\Users\\hongo\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\Local\\pins\\pins\\Cache"

However:

r$> rappdirs::user_cache_dir()
[1] "C:\\Users\\hongo\\AppData\\Local\\cache"
r$> rappdirs::user_cache_dir("AzureR")
[1] "C:\\Users\\hongo\\AppData\\Local\\AzureR\\AzureR\\Cache"
r$> rappdirs::user_data_dir("AzureR")
[1] "C:\\Users\\hongo\\AppData\\Local\\AzureR\\AzureR"

🤨

Meanwhile, switching to one slash type has made the error go away:

r$> f2 <- "c:\\users\\hongo\\documents\\misc\\pins\\tempboard5"
    b <- board_folder(f2)
    b %>% pin_write(mtcars, "mtcars")
Guessing `type = 'rds'`
Replacing version '20210913T140907Z-0fc2e' with '20210913T141549Z-0fc2e'
Writing to pin 'mtcars'

Note that normalizePath seems to be innocent, but path.expand may be the culprit:

r$> f <- "~/misc/pins/tempboard3"
r$> normalizePath(f)
[1] "C:\\Users\\hongo\\Documents\\misc\\pins\\tempboard3"
r$> path.expand(f)
[1] "C:\\Users\\hongo\\Documents/misc/pins/tempboard3"

I've never seen other functions complain about mixed slashes though.

hadley commented 3 years ago

pins mostly uses fs, so this is probably just a matter of me not calling the write fs function in the write place.

github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.