1- if (Sys.info()[' sysname' ] == ' Windows' ){
2- if (! file.exists(" ../build/bin/Debug/thundersvm.dll" )){
3- print(" Please build the library first!" )
4- quit()
1+ check_location <- function (){
2+ if (Sys.info()[' sysname' ] == ' Windows' ){
3+ if (! file.exists(" ../build/bin/Debug/thundersvm.dll" )){
4+ print(" Please build the library first!" )
5+ quit()
6+ }
7+ dyn.load(" ../build/bin/Debug/thundersvm.dll" )
8+ } else if (Sys.info()[' sysname' ] == ' Linux' ){
9+ if (! file.exists(" ../build/lib/libthundersvm.so" )){
10+ print(" Please build the library first!" )
11+ quit()
12+ }
13+ dyn.load(" ../build/lib/libthundersvm.so" )
14+ } else if (Sys.info()[' sysname' ] == ' Darwin' ){
15+ if (! file.exists(" ../build/lib/libthundersvm.dylib" )){
16+ print(" Please build the library first!" )
17+ quit()
18+ }
19+ dyn.load(" ../build/lib/libthundersvm.dylib" )
20+ } else {
21+ print(" OS not supported!" )
22+ quit()
523 }
6- dyn.load(" ../build/bin/Debug/thundersvm.dll" )
7- } else if (Sys.info()[' sysname' ] == ' Linux' ){
8- if (! file.exists(" ../build/lib/libthundersvm.so" )){
9- print(" Please build the library first!" )
10- quit()
11- }
12- dyn.load(" ../build/lib/libthundersvm.so" )
13- } else if (Sys.info()[' sysname' ] == ' Darwin' ){
14- if (! file.exists(" ../build/lib/libthundersvm.dylib" )){
15- print(" Please build the library first!" )
16- quit()
17- }
18- dyn.load(" ../build/lib/libthundersvm.dylib" )
19- } else {
20- print(" OS not supported!" )
21- quit()
2224}
25+ check_location() # Run this when the file is sourced
26+
2327svm_train_R <-
2428function (
2529svm_type = 0 , kernel = 2 ,degree = 3 ,gamma = ' auto' ,
@@ -28,6 +32,8 @@ tol = 0.001, probability = FALSE, class_weight = 'None', cv = '-1',
2832verbose = FALSE , max_iter = - 1 , n_cores = - 1 , dataset = ' None' , model_file = ' None'
2933)
3034{
35+ check_location()
36+ if (! file.exists(dataset )){stop(" The file containing the training dataset provided as an argument in 'dataset' does not exist" )}
3137 res <- .C(" train_R" , as.character(dataset ), as.integer(kernel ), as.integer(svm_type ),
3238 as.integer(degree ), as.character(gamma ), as.double(coef0 ), as.double(nu ),
3339 as.double(cost ), as.double(epsilon ), as.double(tol ), as.integer(probability ),
@@ -40,5 +46,8 @@ function(
4046test_dataset = ' None' , model_file = ' None' , out_file = ' None'
4147)
4248{
49+ check_location()
50+ if (! file.exists(test_dataset )){stop(" The file containing the training dataset provided as an argument in 'test_dataset' does not exist" )}
51+ if (! file.exists(model_file )){stop(" The file containing the model provided as an argument in 'model_file' does not exist" )}
4352 res <- .C(" predict_R" , as.character(test_dataset ), as.character(model_file ), as.character(out_file ))
44- }
53+ }
0 commit comments