Skip to content

Commit

Permalink
add tests and new file
Browse files Browse the repository at this point in the history
  • Loading branch information
wincowgerDEV committed Jan 4, 2024
1 parent 905e58d commit 375aedf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions R/io_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#' read_extdata("raman_hdpe.yml") |> read_spec()
#' read_extdata("raman_hdpe.json") |> read_spec()
#' read_extdata("raman_hdpe.rds") |> read_spec()
#'
#' read_extdata("raman_hdpe.csv") |> read_spec()
#'
#' \dontrun{
#' data(raman_hdpe)
#' write_spec(raman_hdpe, "raman_hdpe.yml")
Expand Down Expand Up @@ -135,7 +136,12 @@ read_spec <- function(file, share = NULL, method = NULL, ...) {
} else if (grepl("\\.rds$", file, ignore.case = T)) {
os <- readRDS(file, ...)
os$metadata$file_name <- basename(file)
} else {
}
else if (grepl("\\.csv$", file, ignore.case = T)) {
os <- read_text(file, ...)
os$metadata$file_name <- basename(file)
}
else {
stop("unknown file type: specify a method to read custom formats or ",
"provide files of one of the supported file types .yml, .json, .rds",
call. = F)
Expand Down
2 changes: 2 additions & 0 deletions inst/extdata/raman_hdpe_os.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
301,305,308,312,315,319,323,326,330,333,337,340,344,348,351,355,358,362,365,369,373,376,380,383,387,390,394,398,401,405,408,412,415,419,422,426,429,433,437,440,444,447,451,454,458,461,465,468,472,475,479,482,486,489,493,496,500,503,507,510,514,518,521,525,528,532,535,539,542,546,549,552,556,559,563,566,570,573,577,580,584,587,591,594,598,601,605,608,612,615,619,622,626,629,632,636,639,643,646,650,653,657,660,664,667,670,674,677,681,684,688,691,694,698,701,705,708,712,715,718,722,725,729,732,736,739,742,746,749,753,756,759,763,766,770,773,777,780,783,787,790,794,797,800,804,807,810,814,817,821,824,827,831,834,838,841,844,848,851,854,858,861,865,868,871,875,878,881,885,888,891,895,898,902,905,908,912,915,918,922,925,928,932,935,938,942,945,948,952,955,958,962,965,968,972,975,978,982,985,988,992,995,998,1002,1005,1008,1011,1015,1018,1021,1025,1028,1031,1035,1038,1041,1045,1048,1051,1054,1058,1061,1064,1068,1071,1074,1077,1081,1084,1087,1091,1094,1097,1100,1104,1107,1110,1113,1117,1120,1123,1127,1130,1133,1136,1140,1143,1146,1149,1153,1156,1159,1162,1166,1169,1172,1175,1179,1182,1185,1188,1192,1195,1198,1201,1205,1208,1211,1214,1217,1221,1224,1227,1230,1234,1237,1240,1243,1247,1250,1253,1256,1259,1263,1266,1269,1272,1275,1279,1282,1285,1288,1291,1295,1298,1301,1304,1307,1311,1314,1317,1320,1323,1327,1330,1333,1336,1339,1343,1346,1349,1352,1355,1358,1362,1365,1368,1371,1374,1377,1381,1384,1387,1390,1393,1396,1400,1403,1406,1409,1412,1415,1419,1422,1425,1428,1431,1434,1437,1441,1444,1447,1450,1453,1456,1459,1463,1466,1469,1472,1475,1478,1481,1485,1488,1491,1494,1497,1500,1503,1506,1510,1513,1516,1519,1522,1525,1528,1531,1534,1538,1541,1544,1547,1550,1553,1556,1559,1562,1565,1569,1572,1575,1578,1581,1584,1587,1590,1593,1596,1599,1603,1606,1609,1612,1615,1618,1621,1624,1627,1630,1633,1636,1639,1643,1646,1649,1652,1655,1658,1661,1664,1667,1670,1673,1676,1679,1682,1685,1688,1691,1695,1698,1701,1704,1707,1710,1713,1716,1719,1722,1725,1728,1731,1734,1737,1740,1743,1746,1749,1752,1755,1758,1761,1764,1767,1770,1773,1776,1779,1782,1785,1788,1791,1794,1798,1801,1804,1807,1810,1813,1816,1819,1822,1825,1828,1831,1834,1837,1840,1843,1846,1849,1852,1854,1857,1860,1863,1866,1869,1872,1875,1878,1881,1884,1887,1890,1893,1896,1899,1902,1905,1908,1911,1914,1917,1920,1923,1926,1929,1932,1935,1937,1940,1943,1946,1949,1952,1955,1958,1961,1964,1967,1970,1973,1976,1979,1982,1985,1988,1991,1994,1997,2000,2003,2005,2008,2011,2014,2017,2020,2023,2026,2029,2032,2035,2038,2041,2044,2047,2050,2052,2055,2058,2061,2064,2067,2070,2073,2076,2079,2082,2085,2088,2090,2093,2096,2099,2102,2105,2108,2111,2114,2117,2120,2122,2125,2128,2131,2134,2137,2140,2143,2146,2149,2151,2154,2157,2160,2163,2166,2169,2172,2174,2177,2180,2183,2186,2189,2192,2195,2198,2200,2203,2206,2209,2212,2215,2218,2221,2223,2226,2229,2232,2235,2238,2241,2243,2246,2249,2252,2255,2258,2261,2263,2266,2269,2272,2275,2278,2280,2283,2286,2289,2292,2295,2298,2300,2303,2306,2309,2312,2315,2317,2320,2323,2326,2329,2332,2334,2337,2340,2343,2346,2348,2351,2354,2357,2360,2363,2365,2368,2371,2374,2377,2379,2382,2385,2388,2391,2393,2396,2399,2402,2405,2407,2410,2413,2416,2419,2421,2424,2427,2430,2433,2435,2438,2441,2444,2447,2449,2452,2455,2458,2460,2463,2466,2469,2472,2474,2477,2480,2483,2485,2488,2491,2494,2497,2499,2502,2505,2508,2510,2513,2516,2519,2521,2524,2527,2530,2532,2535,2538,2541,2543,2546,2549,2552,2554,2557,2560,2563,2565,2568,2571,2574,2576,2579,2582,2585,2587,2590,2593,2596,2598,2601,2604,2606,2609,2612,2615,2617,2620,2623,2626,2628,2631,2634,2636,2639,2642,2645,2647,2650,2653,2655,2658,2661,2664,2666,2669,2672,2674,2677,2680,2682,2685,2688,2691,2693,2696,2699,2701,2704,2707,2709,2712,2715,2717,2720,2723,2726,2728,2731,2734,2736,2739,2742,2744,2747,2750,2752,2755,2758,2760,2763,2766,2768,2771,2774,2776,2779,2782,2784,2787,2790,2792,2795,2798,2800,2803,2806,2808,2811,2814,2816,2819,2822,2824,2827,2830,2832,2835,2837,2840,2843,2845,2848,2851,2853,2856,2859,2861,2864,2867,2869,2872,2874,2877,2880,2882,2885,2888,2890,2893,2895,2898,2901,2903,2906,2909,2911,2914,2916,2919,2922,2924,2927,2930,2932,2935,2937,2940,2943,2945,2948,2950,2953,2956,2958,2961,2963,2966,2969,2971,2974,2976,2979,2982,2984,2987,2989,2992,2995,2997,3000,3002,3005,3008,3010,3013,3015,3018,3020,3023,3026,3028,3031,3033,3036,3038,3041,3044,3046,3049,3051,3054,3057,3059,3062,3064,3067,3069,3072,3074,3077,3080,3082,3085,3087,3090,3092,3095,3098,3100,3103,3105,3108,3110,3113,3115,3118,3120,3123,3126,3128,3131,3133,3136,3138,3141,3143,3146,3148,3151,3154,3156,3159,3161,3164,3166,3169,3171,3174,3175,3178,3180,3183,3185,3188,3191,3193,3196,3198,x,y,user_name,spectrum_type,spectrum_identity,organization,license,session_id,file_id
26,50,48,45,46,42,45,44,48,46,48,44,49,52,48,53,52,46,41,50,62,57,52,45,55,42,52,44,62,57,50,59,48,47,59,58,58,74,69,78,67,73,59,72,65,53,65,63,61,56,47,52,53,58,58,43,54,55,50,47,55,58,50,47,44,55,56,58,54,52,45,64,62,62,57,55,49,65,62,53,55,59,73,63,63,67,77,74,74,79,66,66,67,60,59,48,44,57,61,59,48,59,59,43,50,49,61,58,64,74,49,64,55,55,62,52,62,55,65,54,52,66,54,54,54,60,55,56,53,61,63,53,50,62,62,70,63,61,55,56,70,62,66,60,56,67,57,64,56,51,56,59,61,53,68,64,51,60,62,62,76,65,53,68,53,51,57,53,63,60,74,59,73,51,74,65,64,59,70,61,42,71,66,52,70,67,58,65,64,66,75,59,60,64,63,68,61,53,60,67,57,74,59,64,69,76,59,65,65,75,86,78,70,76,84,78,69,66,83,90,96,128,143,101,81,76,72,85,79,83,67,79,64,80,72,74,70,81,79,82,95,119,148,94,80,71,82,76,76,76,82,73,66,80,79,101,71,83,75,66,72,76,68,88,81,66,67,68,81,67,69,78,68,64,81,83,78,74,67,64,82,72,79,65,84,76,87,75,76,87,82,101,128,200,143,105,101,87,77,88,76,79,95,76,67,82,82,70,82,72,88,66,68,71,84,74,100,83,69,91,81,77,84,75,86,71,92,94,77,93,93,110,112,103,106,110,125,123,169,178,166,129,117,116,127,136,143,127,114,101,85,93,98,87,97,94,95,85,94,93,85,93,74,75,81,105,95,105,105,103,86,85,102,75,72,89,96,92,86,85,90,100,91,88,98,83,84,93,97,71,73,88,78,84,90,97,89,88,86,89,89,89,89,96,98,103,94,91,98,108,80,100,88,101,104,91,96,98,102,96,100,82,87,107,94,105,96,105,106,110,96,88,98,94,99,85,99,93,91,96,94,103,100,106,86,105,100,90,102,100,100,121,121,107,97,94,116,105,100,98,102,107,110,100,107,101,114,106,109,115,116,108,114,112,110,112,108,107,109,109,105,102,107,111,109,108,112,108,102,105,110,108,95,107,99,106,110,115,107,100,108,107,107,113,93,113,124,119,109,101,109,120,112,108,111,116,97,106,114,116,125,109,103,114,122,122,106,124,105,120,105,118,114,105,118,115,112,116,112,132,116,106,115,113,108,136,131,123,108,120,131,121,126,124,137,130,129,119,126,136,135,135,130,130,124,126,122,131,120,140,120,138,128,127,131,146,133,141,124,123,137,131,127,128,123,135,123,121,128,141,136,136,119,114,122,127,135,138,126,125,118,121,129,133,137,131,118,142,103,113,123,110,135,128,133,121,131,118,115,122,124,114,120,136,129,123,119,119,118,114,116,116,120,108,113,114,129,116,110,109,118,103,121,120,108,108,119,130,104,107,95,110,96,117,109,111,111,112,113,112,101,110,107,96,99,105,101,99,103,97,96,108,107,103,103,112,103,115,108,107,102,108,103,102,98,102,98,105,107,95,103,112,112,105,99,105,112,99,99,106,101,97,102,99,99,102,95,109,96,100,99,103,117,100,106,110,96,97,105,98,100,90,94,107,101,92,96,106,105,76,93,104,101,104,95,95,93,81,104,96,101,98,91,103,85,100,87,87,98,100,100,95,114,96,105,106,81,96,104,103,89,108,92,89,96,81,91,100,102,103,99,119,104,97,99,128,116,126,123,130,121,132,115,111,109,102,96,108,104,82,100,107,97,81,100,101,98,98,100,102,97,95,90,93,102,95,103,106,102,99,101,117,101,104,114,112,119,106,116,131,132,148,169,200,303,378,452,489,465,431,388,356,333,318,305,308,305,335,407,576,816,664,494,393,352,318,322,321,308,279,254,257,238,222,214,219,199,207,212,226,206,181,186,162,148,107,119,110,113,101,109,114,105,107,94,91,97,101,87,108,95,103,95,94,96,89,89,105,94,79,85,99,93,84,77,95,92,73,89,98,72,80,81,98,87,81,86,92,85,86,92,86,82,87,86,93,87,88,87,81,82,90,76,90,83,80,75,82,83,76,74,84,83,73,74,77,77,77,81,80,77,75,68,69,77,77,73,74,81,75,68,73,75,76,77,75,77,71,77,71,71,75,75,67,1,1,Win Cowger,Raman,HDPE,Horiba Scientific,CC BY-NC,5728ddde4f649fd71f6f487fc5ad8d80/dc85257201307a131e71d9ec24aaccbf,cb06ce2846b119d932fb6696479a445b
1 change: 1 addition & 0 deletions man/io_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions tests/testthat/test-io_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ test_that("extdata files are present", {
any(grepl("\\.yml$", ed)) |> expect_true()
any(grepl("\\.json$", ed)) |> expect_true()
any(grepl("\\.rds$", ed)) |> expect_true()
any(grepl("\\.csv$", ed)) |> expect_true()
})

test_that("write_spec() works without errors", {
write_spec(raman_hdpe, file.path(tmp, "test.yml")) |> expect_silent()
write_spec(raman_hdpe, file.path(tmp, "test.json")) |> expect_silent()
write_spec(raman_hdpe, file.path(tmp, "test.rds")) |> expect_silent()

write_spec(raman_hdpe, file.path(tmp, "test.csv")) |> expect_silent()

write_spec(as.data.frame(raman_hdpe), file.path(tmp, "test.yml")) |>
expect_error()
write_spec(raman_hdpe, file.path(tmp, "test.csv")) |> expect_error()
write_spec(raman_hdpe, file.path(tmp, "test.flunk")) |> expect_error()
})

test_that("read_spec() gives expected output", {
Expand Down

0 comments on commit 375aedf

Please sign in to comment.