jeffreyevans / spatialEco

R package for spatial analysis and modelling of ecological systems
GNU General Public License v3.0
106 stars 29 forks source link

installation to get sample.distance #42

Closed mwennde closed 2 years ago

mwennde commented 2 years ago

@jeffreyevans I have tried installing spatialEco (using remotes::install_github("jeffreyevans/spatialEco")) to get the version with sample. distance but I get the error sf is not found yet I have sf 1.0.6 version installed ( local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE) if(nchar(pkg)) library(pkg, character.only=TRUE)}) Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE Warning message: package ‘sf’ was built under R version 4.2.0)

Kindly assist

`

remotes::install_github("jeffreyevans/spatialEco") Downloading GitHub repo jeffreyevans/spatialEco@HEAD Skipping 10 packages ahead of CRAN: numDeriv, colorspace, timeDate, zoo, sandwich, latticeExtra, abind, rgdal, multcomp, yaImpute

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

√ checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION'

√ checking DESCRIPTION meta-information

Installing package into ‘C:/Users/pc/Documents/R/win-library/4.1’ (as ‘lib’ is unspecified)

jeffreyevans commented 2 years ago

Unfortunately, this is a package install, control issue that the spatialEco package has no control over. These required package environments are only designated by a package, with R managing the actually dependency. If a packages is not finding a required environment it either does not exist or something about how R is managing library paths is not allowing access.

It looks like you are aiming at the “library” directory under your R install so, personal libraries should not be a problem here. Do you have root permissions for this directory? At this point, all I can recommend is making sure that your permissions are open for the library and, delete the sf install and reinstall it. I would also suggest using the dependencies=TRUE argument in your call to remotes::install_github.

Please let me know if I can help further.

Best, Jeff

Jeffrey S. Evans, Ph.D., | Senior Landscape Ecologist & Biometrician The Nature Conservancy | Global Protect, Science Visiting Professor | University of Wyoming | Zoology & Physiology Laramie, WY | @.**@.> | (970) 672-6766<tel:(970)%20672-6766>

From: mwennde @.> Sent: Sunday, February 6, 2022 8:16 AM To: jeffreyevans/spatialEco @.> Cc: Jeffrey Evans @.>; Mention @.> Subject: [jeffreyevans/spatialEco] installation to get sample.distance (Issue #42)

@jeffreyevanshttps://github.com/jeffreyevans I have tried installing spatialEco (using remotes::install_github("jeffreyevans/spatialEco")) to get the version with sample. distance but I get the error sf is not found yet I have sf 1.0.6 version installed ( local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE) if(nchar(pkg)) library(pkg, character.only=TRUE)}) Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE Warning message: package ‘sf’ was built under R version 4.2.0 )

Kindly assist

` update.packages(ask='graphics',checkBuilt=TRUE) Warning: package 'class' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'foreign' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'MASS' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'Matrix' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'nlme' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'nnet' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'rpart' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'spatial' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated

utils:::menuInstallLocal() package ‘spatialEco’ successfully unpacked and MD5 sums checked remotes::install_github("jeffreyevans/spatialEco") Downloading GitHub repo @.*** Skipping 10 packages ahead of CRAN: numDeriv, colorspace, timeDate, zoo, sandwich, latticeExtra, abind, rgdal, multcomp, yaImpute

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

√ checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION'

checking DESCRIPTION meta-information ...

√ checking DESCRIPTION meta-information

Installing package into ‘C:/Users/pc/Documents/R/win-library/4.1’ (as ‘lib’ is unspecified)

`

— Reply to this email directly, view it on GitHubhttps://github.com/jeffreyevans/spatialEco/issues/42, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACLKH74OIR6OICWZE46GPG3UZ2GE3ANCNFSM5NVOKYKA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.**@.>>

jeffreyevans commented 2 years ago

Also, as a follow up, you can source a function from GitHub using the devtools package. However, be cautious doing this with packages because it will not bring along any dependencies (eg., other required functions from the package). In the case of subsample.distance it is safe but, it requires the sp package be installed to work.

devtools::source_url("https://github.com/jeffreyevans/spatialEco/blob/master/R/subsample.distance.R?raw=TRUE ")

Best, Jeff

From: mwennde @.> Sent: Sunday, February 6, 2022 8:16 AM To: jeffreyevans/spatialEco @.> Cc: Jeffrey Evans @.>; Mention @.> Subject: [jeffreyevans/spatialEco] installation to get sample.distance (Issue #42)

@jeffreyevanshttps://github.com/jeffreyevans I have tried installing spatialEco (using remotes::install_github("jeffreyevans/spatialEco")) to get the version with sample. distance but I get the error sf is not found yet I have sf 1.0.6 version installed ( local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE) if(nchar(pkg)) library(pkg, character.only=TRUE)}) Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE Warning message: package ‘sf’ was built under R version 4.2.0 )

Kindly assist

` update.packages(ask='graphics',checkBuilt=TRUE) Warning: package 'class' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'foreign' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'MASS' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'Matrix' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'nlme' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'nnet' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'rpart' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'spatial' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated

utils:::menuInstallLocal() package ‘spatialEco’ successfully unpacked and MD5 sums checked remotes::install_github("jeffreyevans/spatialEco") Downloading GitHub repo @.*** Skipping 10 packages ahead of CRAN: numDeriv, colorspace, timeDate, zoo, sandwich, latticeExtra, abind, rgdal, multcomp, yaImpute

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

√ checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION'

checking DESCRIPTION meta-information ...

√ checking DESCRIPTION meta-information

Installing package into ‘C:/Users/pc/Documents/R/win-library/4.1’ (as ‘lib’ is unspecified)

`

— Reply to this email directly, view it on GitHubhttps://github.com/jeffreyevans/spatialEco/issues/42, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACLKH74OIR6OICWZE46GPG3UZ2GE3ANCNFSM5NVOKYKA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.**@.>>

jeffreyevans commented 2 years ago

It is looking like there are some version dependency conflicts going on in terra and sf under R 4.1.2. The terra package needs version 1.5-1 to run under R 4.1.2 and does not update automatically when another package is installed that requires it as a dependency. So, if it is a previous version you will receive an error. Lately, it has been taking some time for packages to be converted to binary under windows distribution so, unless you have RTools installed and your package defaults are set to “compile from source”, then any requested update is skipped. Every once in a while, these versioning conflicts occur and eventually resolve themselves, as they did with the release of R 4.0.0. I would recommend performing fresh installs of sf, sp, terra, raster and, rgdal before installing spatialEco.

BTW, the subsample.distance function is available in the stable CRAN release. Why are you downloading the development version?

Best, Jeff

From: mwennde @.> Sent: Sunday, February 6, 2022 8:16 AM To: jeffreyevans/spatialEco @.> Cc: Jeffrey Evans @.>; Mention @.> Subject: [jeffreyevans/spatialEco] installation to get sample.distance (Issue #42)

@jeffreyevanshttps://github.com/jeffreyevans I have tried installing spatialEco (using remotes::install_github("jeffreyevans/spatialEco")) to get the version with sample. distance but I get the error sf is not found yet I have sf 1.0.6 version installed ( local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE) if(nchar(pkg)) library(pkg, character.only=TRUE)}) Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE Warning message: package ‘sf’ was built under R version 4.2.0 )

Kindly assist

` update.packages(ask='graphics',checkBuilt=TRUE) Warning: package 'class' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'foreign' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'MASS' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'Matrix' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'nlme' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'nnet' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'rpart' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated Warning: package 'spatial' in library 'C:/Program Files/R/R-4.1.2/library' will not be updated

utils:::menuInstallLocal() package ‘spatialEco’ successfully unpacked and MD5 sums checked remotes::install_github("jeffreyevans/spatialEco") Downloading GitHub repo @.*** Skipping 10 packages ahead of CRAN: numDeriv, colorspace, timeDate, zoo, sandwich, latticeExtra, abind, rgdal, multcomp, yaImpute

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION' ...

√ checking for file 'C:\Users\pc\AppData\Local\Temp\RtmpiKsqfA\remotes31d83a9d3d34\jeffreyevans-spatialEco-76d5739/DESCRIPTION'

checking DESCRIPTION meta-information ...

√ checking DESCRIPTION meta-information

Installing package into ‘C:/Users/pc/Documents/R/win-library/4.1’ (as ‘lib’ is unspecified)

`

— Reply to this email directly, view it on GitHubhttps://github.com/jeffreyevans/spatialEco/issues/42, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACLKH74OIR6OICWZE46GPG3UZ2GE3ANCNFSM5NVOKYKA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.**@.>>

mwennde commented 2 years ago

@jeffreyevans Thank you Jeffrey for addressing my issue. Initially was using a sample. annulus but because of proj4string could not get any output (I need to get a random sample for my (a 4 kilometres minimum distance between any pair of control and treatment village. )

subsample.distance picks only one village sub.s <- subsample.distance(s, size = 50, d = 500, d.max = 4000) (I have 120 villages and 50 should be in the treatment)

Then I saw the discussion suggesting the use of sample. distance [https://gis.stackexchange.com/questions/299625/random-selection-of-points-in-spatialpointsdataframe-r-object-with-distance-cons]

`> library(sp)

library(spatialEco)

Attaching package: ‘spatialEco’

The following object is masked from ‘package:dplyr’:

combine

Warning message: package ‘spatialEco’ was built under R version 4.2.0

data(meuse) coordinates(meuse) <- ~ x+y sub.meuse <- sample.distance(meuse, n = p, d = 500, trace = TRUE)
Error in sample.distance(meuse, n = p, d = 500, trace = TRUE) : could not find function "sample.distance" plot(meuse,pch=19, main="min dist = 500") points(sub.meuse, pch=19, col="red") Ire `

jeffreyevans commented 2 years ago

The post you are referencing is from 2018 so, the function got moved into the package long ago. Please note that it is “subsample.distance” due to it being a subsampling and not a sample generation approach.

What was your problem with sample.annulus? If the data is in a geographic projection rgeos does not like it and issues an error regarding planar coordinates. Were you missing a projection definition or was it geographic? This sounds like a more appropriate solution for your problem and I can likely get the function working for you without too much work.

-jeff

From: mwennde @.> Sent: Tuesday, February 8, 2022 12:51 PM To: jeffreyevans/spatialEco @.> Cc: Jeffrey Evans @.>; Mention @.> Subject: Re: [jeffreyevans/spatialEco] installation to get sample.distance (Issue #42)

Thank you Jeffrey for addressing my issue. Initially was using a sample. annulus but because of proj4string could not get any output (I need to get a random sample for my (a 4 kilometres minimum distance between any pair of control and treatment village. )

subsample.distance picks only one village sub.s <- subsample.distance(s, size = 50, d = 500, d.max = 4000) (I have 120 villages and 50 should be in the treatment)

Then I saw the discussion suggesting the use of sample. distance [https://gis.stackexchange.com/questions/299625/random-selection-of-points-in-spatialpointsdataframe-r-object-with-distance-conshttps://gis.stackexchange.com/questions/299625/random-selection-of-points-in-spatialpointsdataframe-r-object-with-distance-cons]

`> library(sp)

library(spatialEco)

Attaching package: ‘spatialEco’

The following object is masked from ‘package:dplyr’:

combine

Warning message: package ‘spatialEco’ was built under R version 4.2.0

data(meuse) coordinates(meuse) <- ~ x+y sub.meuse <- sample.distance(meuse, n = p, d = 500, trace = TRUE) Error in sample.distance(meuse, n = p, d = 500, trace = TRUE) : could not find function "sample.distance" plot(meuse,pch=19, main="min dist = 500") points(sub.meuse, pch=19, col="red") Ire `

— Reply to this email directly, view it on GitHubhttps://github.com/jeffreyevans/spatialEco/issues/42#issuecomment-1033000109, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACLKH7YIU7AYIKC7QYT5WTLU2FXZ5ANCNFSM5NVOKYKA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.**@.>>

mwennde commented 2 years ago

The error with sample.annulus . ` library(sp)

library(rgeos) data(meuse) coordinates(meuse) <- ~x+y proj4string(meuse) <- CRS("+init=epsg:28992") xy <- meuse[2,] rs100 <- sample.annulus(xy, r1=50, r2=100, n = 50, type = "random") Warning message: In proj4string(obj) : CRS object has comment, which is lost in output; in tests, see https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html `

jeffreyevans commented 2 years ago

This is a non-error, just a warning message regarding the way proj4 comments and datums are now being handled with the changes to PROJ and GDAL. This warning message is not effecting output. Do note that warning messages are common in R and often do not effect output whereas and error message indicates that the function has stopped with an error condition, without providing output.

You can suppress this message, coming from rgdal, by issuing: options("rgdal_show_exportToProj4_warnings"="none") before adding any packages or by putting it in your start up “Rprofile.site” file.

In fact, you can just sidestep the entire issue and assign a WKT2 projection format to your object in the first place (following the new standard). For an sp object you have to access the "proj4string" slot whereas for sf objects you can simply use an assignment pipe st_crs(obj) <- st_crs(EPSG) Here is an example on the code block that you sent.

library(sp)
library(spatialEco)
rgdal::rgdal_extSoftVersion()

data(meuse, package = "sp")
  coordinates(meuse) <- ~x+y
    slot(meuse, "proj4string") <- CRS(SRS_string = "EPSG:28992")

xy <- meuse[2,]
rs100 <- sample.annulus(xy, r1=50, r2=100, n = 50, type = "random")
rs200 <- sample.annulus(xy, r1=100, r2=200, n = 50, type = "random")

plot(rs200, pch=20, col="red")
  points(rs100, pch=20, col="blue")
  points(xy, pch=20, cex=2, col="black")
  box()
  legend("topright", legend=c("50-100m", "100-200m", "source"),
         pch=c(20,20,20), col=c("blue","red","black"))

#### Or, for projection assignment for an sf object (although you can do this
#### directly in the st_as_sf function with the crs argument).
data(meuse, package = "sp")
meuse <- st_as_sf(meuse, coords = c("x", "y"), = "constant")
    st_crs(meuse) <- st_crs(28992)

-jeff

From: mwennde @.> Sent: Tuesday, February 8, 2022 2:46 PM To: jeffreyevans/spatialEco @.> Cc: Jeffrey Evans @.>; Mention @.> Subject: Re: [jeffreyevans/spatialEco] installation to get sample.distance (Issue #42)

The error with sample.annulus . ` library(sp)

library(rgeos) data(meuse) coordinates(meuse) <- ~x+y proj4string(meuse) <- CRS("+init=epsg:28992") xy <- meuse[2,] rs100 <- sample.annulus(xy, r1=50, r2=100, n = 50, type = "random") Warning message: In proj4string(obj) : CRS object has comment, which is lost in output; in tests, see https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.htmlhttps://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html `

— Reply to this email directly, view it on GitHubhttps://github.com/jeffreyevans/spatialEco/issues/42#issuecomment-1033092458, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACLKH75ZGINX6BEO2AD635LU2GFJJANCNFSM5NVOKYKA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.**@.>>

mwennde commented 2 years ago

Thank you. I will then use the sample. annulus