rekonstrukt / swedishbutterflies

Swedish Butterflies - tools and apps
GNU Affero General Public License v3.0
1 stars 3 forks source link

Config file error on Win7 #16

Open larspett opened 5 years ago

larspett commented 5 years ago

I am unable to load the config.yml from its proper place due to a directory mismatch that I am unsure if it was around in previous versions.

having the yml file in this directory: C:\Users\Lars\AppData\Local\sebms\config.yml

I get the following error: "(...) Config file used: C:\Users\Lars\AppData\Local\sebms\sebms/config.yml, timestamp: 2018-11-05 16:33:59 (...)" with a duplication of the directory and an incorrect slash.

The session info is as follows:

devtools::session_info()

  • Session info ------------------------------------------------------------------------------------------ setting value
    version R version 3.5.1 (2018-07-02) os Windows 7 x64 SP 1
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate Swedish_Sweden.1252
    ctype Swedish_Sweden.1252
    tz Europe/Berlin
    date 2018-11-05

[1] C:/Users/Lars/Documents/R/win-library/3.5 [2] C:/Program Files/R/R-3.5.1/library

devtools::loadall("~/R/win-library/3.5/swedishbutterflies") Loading swedishbutterflies Cannot connect to SeBMS db, are credentials invalid and/or do you need an ssh tunnel? Config file used: C:\Users\Lars\AppData\Local\sebms\sebms/config.yml, timestamp: 2018-11-05 16:33:59 Using dbuser: with more connection details in the config file Now proceeding without valid db connection... Please enable db connections for full functionality (edit settings in config.yml and/or run ssh tunnels?) https://dagfjarilar.lu.se__
.-----.--.--.--.-----.--| ||.-----.| |--. | --| | | | -__|
| || --|| | |_|__|_|_|_||||||


| |--.--.--.| || |.-----.----.' _| ||.-----.-----. | | | || | _| -| | | | || -|__ --| |___||||||| || |||||| Use runShinyApp('poc') to run the Shiny proof-of-concept app

larspett commented 5 years ago

.Platform$file.sep [1] "/"

larspett commented 5 years ago

I asked Carsten now to see if he gets the same error. Slashes to the config.yml are double, the sebms directory where it resides is pasted twice and the last slash is / rather than \

It appears that cfgfile <- file.path(rappdirs::app_dir("sebms")$config(), "config.yml") results in "C:\Users\Lars\AppData\Local\sebms\sebms/config.yml" when it is actually found here: C:\Users\Lars\AppData\Local\sebms\config.yml

CarstenKost commented 5 years ago

Hello!

I get the same problem:

> cfgfile <- file.path(rappdirs::app_dir("sebms")$config(), "config.yml")
> cfgfile
[1] "C:\\Users\\Carsten Kost\\AppData\\Local\\sebms\\sebms/config.yml"

"config.yml" is in the folder "C:\Users\Carsten Kost\AppData\Local\sebms\sebms" on my system.

All the best,

Carsten

Session info ------------------------------------------------------------------------------------------------- setting value
version R version 3.5.1 (2018-07-02) system x86_64, mingw32
ui RStudio (1.1.456)
language (EN)
collate English_Sweden.1252
tz Europe/Berlin
date 2018-11-08

Packages ----------------------------------------------------------------------------------------------------- package version date source
abind 1.4-5 2016-07-21 CRAN (R 3.5.0)
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.1)
backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
base
3.5.1 2018-07-02 local
bindr 0.1.1 2018-03-13 CRAN (R 3.5.1)
bindrcpp 0.2.2 2018-03-29 CRAN (R 3.5.1)
bit 1.1-14 2018-05-29 CRAN (R 3.5.0)
bit64 0.9-7 2017-05-08 CRAN (R 3.5.0)
blob 1.1.1 2018-03-25 CRAN (R 3.5.1)
broom 0.5.0 2018-07-17 CRAN (R 3.5.1)
car
3.0-0 2018-04-02 CRAN (R 3.5.1)
carData 3.0-1 2018-03-28 CRAN (R 3.5.0)
cellranger 1.1.0 2016-07-27 CRAN (R 3.5.1)
cli 1.0.0 2017-11-05 CRAN (R 3.5.1)
colorspace 1.3-2 2016-12-14 CRAN (R 3.5.1)
compiler 3.5.1 2018-07-02 local
config
0.3 2018-03-27 CRAN (R 3.5.1)
cowplot 0.9.3 2018-07-15 CRAN (R 3.5.1)
crayon 1.3.4 2017-09-16 CRAN (R 3.5.1)
crosstalk 1.0.0 2016-12-21 CRAN (R 3.5.1)
curl 3.2 2018-03-28 CRAN (R 3.5.1)
data.table 1.11.4 2018-05-27 CRAN (R 3.5.1)
datasets 3.5.1 2018-07-02 local
DBI
1.0.0 2018-05-02 CRAN (R 3.5.1)
dbplyr 1.2.2 2018-07-25 CRAN (R 3.5.1)
devtools 1.13.6 2018-06-27 CRAN (R 3.5.1)
digest 0.6.15 2018-01-28 CRAN (R 3.5.1)
dplyr
0.7.6 2018-06-29 CRAN (R 3.5.1)
forcats 0.3.0 2018-02-19 CRAN (R 3.5.1)
foreign 0.8-70 2017-11-28 CRAN (R 3.5.1)
ggplot2
3.0.0 2018-07-03 CRAN (R 3.5.1)
ggthemes 4.0.0 2018-07-19 CRAN (R 3.5.1)
glue 1.3.0 2018-07-17 CRAN (R 3.5.1)
graphics 3.5.1 2018-07-02 local
grDevices
3.5.1 2018-07-02 local
grid 3.5.1 2018-07-02 local
gtable 0.2.0 2016-02-26 CRAN (R 3.5.1)
haven 1.1.2 2018-06-27 CRAN (R 3.5.1)
hexbin 1.27.2 2018-01-15 CRAN (R 3.5.1)
hms 0.4.2 2018-03-10 CRAN (R 3.5.1)
htmltools 0.3.6 2017-04-28 CRAN (R 3.5.1)
htmlwidgets 1.2 2018-04-19 CRAN (R 3.5.1)
httpuv 1.4.5 2018-07-19 CRAN (R 3.5.1)
httr 1.3.1 2017-08-20 CRAN (R 3.5.1)
jsonlite 1.5 2017-06-01 CRAN (R 3.5.1)
knitr 1.20 2018-02-20 CRAN (R 3.5.1)
labeling 0.3 2014-08-23 CRAN (R 3.5.0)
later 0.7.3 2018-06-08 CRAN (R 3.5.1)
lattice 0.20-35 2017-03-25 CRAN (R 3.5.1)
latticeExtra 0.6-28 2016-02-09 CRAN (R 3.5.1)
lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.1)
leaflet 2.0.1 2018-06-04 CRAN (R 3.5.1)
lubridate 1.7.4 2018-04-11 CRAN (R 3.5.1)
magick
1.9 2018-05-11 CRAN (R 3.5.1)
magrittr 1.5 2014-11-22 CRAN (R 3.5.1)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.1)
methods 3.5.1 2018-07-02 local
mime 0.5 2016-07-07 CRAN (R 3.5.0)
modelr 0.1.2 2018-05-11 CRAN (R 3.5.1)
munsell 0.5.0 2018-06-12 CRAN (R 3.5.1)
nlme 3.1-137 2018-04-07 CRAN (R 3.5.1)
openxlsx 4.1.0 2018-05-26 CRAN (R 3.5.1)
parallel 3.5.1 2018-07-02 local
pillar 1.3.0 2018-07-14 CRAN (R 3.5.1)
pkgconfig 2.0.1 2017-03-21 CRAN (R 3.5.1)
plyr 1.8.4 2016-06-08 CRAN (R 3.5.1)
pool
0.1.4.1 2018-06-29 CRAN (R 3.5.1)
promises 1.0.1 2018-04-13 CRAN (R 3.5.1)
purrr 0.2.5 2018-05-29 CRAN (R 3.5.1)
R6 2.2.2 2017-06-17 CRAN (R 3.5.1)
rappdirs
0.3.1 2016-03-28 CRAN (R 3.5.1)
raster 2.6-7 2017-11-13 CRAN (R 3.5.1)
rasterVis 0.45 2018-06-02 CRAN (R 3.5.1)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.5.0)
Rcpp 0.12.18 2018-07-23 CRAN (R 3.5.1)
readr
1.1.1 2017-05-16 CRAN (R 3.5.1)
readxl 1.1.0 2018-04-20 CRAN (R 3.5.1)
rgdal 1.3-4 2018-08-03 CRAN (R 3.5.1)
rio 0.5.10 2018-03-29 CRAN (R 3.5.1)
rlang 0.2.1 2018-05-30 CRAN (R 3.5.1)
RPostgres 1.1.1 2018-05-06 CRAN (R 3.5.1)
RPostgreSQL
0.6-2 2017-06-24 CRAN (R 3.5.1)
rstudioapi 0.7 2017-09-07 CRAN (R 3.5.1)
rtrim
2.0.4 2018-03-15 CRAN (R 3.5.1)
rvest 0.3.2 2016-06-17 CRAN (R 3.5.1)
scales 0.5.0 2017-08-24 CRAN (R 3.5.1)
shiny 1.1.0 2018-05-17 CRAN (R 3.5.1)
sp 1.3-1 2018-06-05 CRAN (R 3.5.1)
stats
3.5.1 2018-07-02 local
stringi 1.1.7 2018-03-12 CRAN (R 3.5.0)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.1)
swedishbutterflies
0.1.3 2018-08-21 Github (rekonstrukt/swedishbutterflies@2848c1d) tibble 1.4.2 2018-01-22 CRAN (R 3.5.1)
tidyr
0.8.1 2018-05-18 CRAN (R 3.5.1)
tidyselect 0.2.4 2018-02-26 CRAN (R 3.5.1)
tidyverse 1.2.1 2017-11-14 CRAN (R 3.5.1)
tools 3.5.1 2018-07-02 local
utils
3.5.1 2018-07-02 local
viridisLite 0.3.0 2018-02-01 CRAN (R 3.5.1)
withr 2.1.2 2018-03-15 CRAN (R 3.5.1)
xml2 1.2.0 2018-01-24 CRAN (R 3.5.1)
xtable 1.8-2 2016-02-05 CRAN (R 3.5.1)
yaml 2.2.0 2018-07-25 CRAN (R 3.5.1)
zip 1.0.0 2017-04-25 CRAN (R 3.5.1)
zoo 1.8-3 2018-07-16 CRAN (R 3.5.1)

larspett commented 5 years ago

This looks like it generates a correct path on Win7 but it still doesn't recognise the tunnel even though it is up

file.path(rappdirs::app_dir("sebms", appauthor=NULL)$config(),'config.yml', fsep = '\')

The double directories was mentioned in an issue at github/rappdir (but is correct behaviuor), the slashes are more difficult why the don't adapt but single '/' seems to be the default behaviour in file.path on windows

I have tried with expand=FALSE too but it doesn't seem necessary. Am unusr eif this code would work on other OSes

rekonstrukt commented 5 years ago

I made a fix now that I hope resolves this issue. It has been pushed now and it makes use of normalizePath which converts file paths to canonical form for the platform.

I added a test and ran tests on Linux and a Windows VM with success. The build also went through on Travis (see https://travis-ci.org/rekonstrukt/swedishbutterflies/builds).

The Win VM I used has the config.yml at the following location: Config file used: C:\Users\IEUser\AppData\Local\sebms\sebms\config.yml

Please have a look and please go ahead and close this issue if you get the expected behaviour.

To install the version that has this fix, the following command can be used:

library(devtools)
install_github("rekonstrukt/swedishbutterflies@0.1.7")
larspett commented 5 years ago

Unfortunately it still won't work. I have a tunnel up and running (checked with PGAdmin) but the package will not connect. I am unsure if it really reads the config.yml file since it is correct. It looks for the file at C:\Users\Lars\AppData\Local\sebms\sebms\config.yml while the real (visible) path is C:\Users\Lars\AppData\Local\sebms\config.yml. I assume the "extra sebms" is correct for being on windows but to double check, I moved the config.yml into another folder to mimick "C:\Users\Lars\AppData\Local\sebms\sebms\config.yml". Still no success.

running library(butterflies) gives

Cannot connect to SeBMS db, are credentials invalid and/or do you need an ssh tunnel? Config file used: C:\Users\Lars\AppData\Local\sebms\sebms\config.yml, timestamp: 2018-11-12 08:56:57 Using dbuser: with more connection details in the config file Now proceeding without valid db connection... Please enable db connections for full functionality (edit settings in config.yml and/or run ssh tunnels?)

The install_github("rekonstrukt/swedishbutterflies@0.1.7") gives the same response

session_info()

  • Session info ------------------------------------------------------------------------------------------ setting value
    version R version 3.5.1 (2018-07-02) os Windows 7 x64 SP 1
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate Swedish_Sweden.1252
    ctype Swedish_Sweden.1252
    tz Europe/Berlin
    date 2018-11-12

[1] C:/Users/Lars/Documents/R/win-library/3.5 [2] C:/Program Files/R/R-3.5.1/library

rekonstrukt commented 5 years ago

I have installed a VM with Windows 7 now and installed the stack from scratch (R, Rtools, RStudio and the packages required for running swedishbutterflies). I think the issue might be with the environment variables and if this is so, it can be verified by running this at the R console:

Sys.getenv("DBUSER")

If this doesn't print the expected value for the database user, you can fix this and make R aware of the two required environment variables used in the default config.yml setup by providing them in the .Renviron text file, you can open this config file using the following commands from the R console:


library(rappdirs)
library(usethis)

# check the two config files used and verify their contents in the RStudio editor
edit_file(normalizePath(file.path(Sys.getenv("R_USER"), ".Renviron")))
edit_file(normalizePath(file.path(app_dir("sebms")$config(), "config.yml")))

# restart RStudio to re-read the .Renviron file with the environment variables
# then verify that the values are in the environment with this command

Sys.getenv("DBUSER")

# when loading the "swedishbutterflies" package,
# you can then verify that you can get data from the db for example
# with this code:

library(swedishbutterflies)
library(dplyr)
library(knitr)

sebms_species_per_year() %>% head(5) %>% kable()

Please let me know if this helps in resolving this issue.

CarstenKost commented 5 years ago

Hello!

Unfortunately the issue persists for me.

Sys.getenv("DBUSER") returns the correct user name and the tunnel is up.

file.path(rappdirs::app_dir("sebms")$config(), "config.yml") still returns "C:\\Users\\carst\\AppData\\Local\\sebms\\sebms/config.yml"

I cannot connect to the database when loading the package, regardless of whether I write my credentials directly into config.yml or get them from the environment variables. I am using the newest version of the package and have recently reset my system.

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] swedishbutterflies_0.1.7

loaded via a namespace (and not attached):
 [1] zoo_1.8-4           tidyselect_0.2.5    purrr_0.2.5         lattice_0.20-38     ggthemes_4.0.1      colorspace_1.3-2    viridisLite_0.3.0   htmltools_0.3.6    
 [9] yaml_2.2.0          blob_1.1.1          rlang_0.3.0.1       hexbin_1.27.2       pillar_1.3.1        later_0.7.5         glue_1.3.0          DBI_1.0.0          
[17] rappdirs_0.3.1      sp_1.3-1            bit64_0.9-7         RColorBrewer_1.1-2  dbplyr_1.2.2        bindrcpp_0.2.2      bindr_0.1.1         plyr_1.8.4         
[25] stringr_1.3.1       munsell_0.5.0       gtable_0.2.0        raster_2.8-4        htmlwidgets_1.3     codetools_0.2-15    latticeExtra_0.6-28 httpuv_1.4.5       
[33] crosstalk_1.0.0     parallel_3.5.2      Rcpp_1.0.0          xtable_1.8-3        scales_1.0.0        promises_1.0.1      leaflet_2.0.2       magick_2.0         
[41] jsonlite_1.6        config_0.3          mime_0.6            bit_1.1-14          ggplot2_3.1.0       hms_0.4.2           digest_0.6.18       stringi_1.2.4      
[49] rasterVis_0.45      dplyr_0.7.8         shiny_1.2.0         grid_3.5.2          cowplot_0.9.3       tools_3.5.2         magrittr_1.5        lazyeval_0.2.1     
[57] tibble_1.4.2        crayon_1.3.4        tidyr_0.8.2         pool_0.1.4.1        pkgconfig_2.0.2     lubridate_1.7.4     assertthat_0.2.0    rstudioapi_0.8     
[65] RPostgres_1.1.1     R6_2.3.0            compiler_3.5.2