@@ -637,7 +637,7 @@ setMethod(
637637setMethod(
638638 " .check_vector" ,
639639 signature(input = " sf" , input_id = " ANY" ,
640- extent = " NULL " , out_class = " character" ),
640+ extent = " ANY " , out_class = " character" ),
641641 function (input , input_id , extent , out_class , ... ) {
642642 .check_pkgname(out = out_class )
643643 input <- .check_id(input , input_id )
@@ -694,6 +694,7 @@ setMethod(
694694)
695695
696696
697+
697698# ' @keywords internal
698699# ' @name .check_vector
699700# ' @rdname .check_vector
@@ -825,7 +826,7 @@ setMethod(
825826setMethod(
826827 " .check_vector" ,
827828 signature(input = " SpatVector" , input_id = " ANY" ,
828- extent = " NULL " , out_class = " character" ),
829+ extent = " ANY " , out_class = " character" ),
829830 function (input , input_id , extent , out_class , ... ) {
830831 .check_pkgname(out = out_class )
831832
@@ -952,7 +953,7 @@ setMethod(
952953 # character ingestion
953954 if (is.character(input )) {
954955 cli :: cli_inform(
955- sprintf( " Input is a character. Attempt to read it with terra::rast...\n " )
956+ " Input is a character. Attempt to read it with terra::rast...\n "
956957 )
957958 input <-
958959 try(terra :: rast(input , win = extent , snap = " out" ), silent = TRUE )
@@ -985,9 +986,20 @@ setMethod(
985986 )
986987 )
987988 suppressWarnings(
988- input <- try(terra :: sources(input ), silent = TRUE )
989+ input_read <- try(terra :: sources(input ), silent = TRUE )
989990 )
990- if (inherits(input , " try-error" )) {
991+ if (is.character(input_read )) {
992+ if (input_read == " " ) {
993+ path_temp <- tempfile(fileext = " .tif" )
994+ cli :: cli_alert_info(
995+ " The data is in memory. Writing a temporary GeoTIFF file to track the data source path..."
996+ )
997+ terra :: writeRaster(input , path_temp , overwrite = TRUE )
998+ input_read <- path_temp
999+ }
1000+ return (input_read )
1001+ }
1002+ if (inherits(input_read , " try-error" )) {
9911003 cli :: cli_abort(
9921004 paste0(
9931005 " Failed to track the data source file path.\n " ,
@@ -996,8 +1008,9 @@ setMethod(
9961008 )
9971009 }
9981010 }
1011+ input
9991012 }
1000- return ( input )
1013+ input
10011014}
10021015
10031016
@@ -1022,22 +1035,26 @@ setMethod(
10221035 )[[1 ]]
10231036 ),
10241037 error = function (e ) {
1025- " error"
1038+ if (exists(fun )) {
1039+ " user"
1040+ } else {
1041+ " error"
1042+ }
10261043 }
10271044 )
10281045 },
10291046 FUN.VALUE = character (1 )
10301047 )
10311048
1032- pkgname <- grep(" ^(terra|sf|chopin)$" , pkgname , value = TRUE )
1049+ pkgname <- grep(" ^(terra|sf|chopin|user )$" , pkgname , value = TRUE )
10331050 if (length(pkgname ) == 0 ) {
10341051 cli :: cli_abort(" No parent package is found." )
10351052 }
10361053 if (length(pkgname ) > 1 ) {
10371054 cli :: cli_abort(" There are multiple parent packages matched." )
10381055 }
1039- if (! pkgname %in% c(" sf" , " terra" , " chopin" )) {
1040- cli :: cli_abort(" Function should be one from sf, terra, or chopin." )
1056+ if (! pkgname %in% c(" sf" , " terra" , " chopin" , " user " )) {
1057+ cli :: cli_abort(" Function should be user-defined or one from sf, terra, or chopin." )
10411058 }
10421059 return (pkgname )
10431060 }
0 commit comments