R读入最新版本的文件

时间:2016-03-15 15:06:12

标签: r

我目前正在读一个类似下面例子的文件,有没有办法指定读取文件的最新版本,即如果我将文件保存为“Abroad v1.csv”,“Abroad v2.csv”I我希望它采取最新的,在这种情况下将是2。

year <- "2015"
species <- "HOM"

root <- "Y:/Pelagic Work/FIN Data"
file <- "Abroad.csv"
ABR <- file.path(root, year, species, file)

1 个答案:

答案 0 :(得分:1)

如果合理的话,最好确定最新的&#34; <select name="countryselect" id="countryselect"> <?php $db = pg_connect('host=localhost dbname=test user=myuser password=mypass'); $query = "SELECT country FROM countries"; $result = pg_query($query); if (!$result) { echo "Problem with query " . $query . "<br/>"; echo pg_last_error(); exit(); } printf ("<option value=Select>Select a Country</option>"); while($myrow = pg_fetch_assoc($result)) { printf ("<option value=$myrow[country]>$myrow[country]</option>"); } ?> </select> <input type="submit" name="submit" value="SAVE"> </form> <?php if ($nameErr == '' && $emailErr == '' && $surnameErr == '') { $db = pg_connect('host=localhost dbname=test user=myuser password=mypass'); $firstname = pg_escape_string($_POST['name']); $surname = pg_escape_string($_POST['surname']); $emailaddress = pg_escape_string($_POST['email']); $query = "INSERT INTO host(firstname, surname, emailaddress) VALUES('" . $firstname . "', '" . $surname . "', '" . $emailaddress . "')"; $result = pg_query($db, $query); if (!$result) { $errormessage = pg_last_error(); echo "Error with query: " . $errormessage; exit(); } //printf ("These values were inserted into the database - %s %s %s", $firstname, $surname, $emailaddress); pg_close(); } ?> </body> </html> 输出(this post中的数据的文件版本,也是zx8754建议的,这是一个很好的答案。)

如果必须按文件名进行,请务必小心并了解操作系统如何对字符进行排序。举个例子,举个例子。

file.info

如您所见,files <- paste0("somepath/directory/filename v", 1:10, ".csv") basenames <- basename(files) sort(basenames) [1] "filename v1.csv" "filename v10.csv" "filename v2.csv" "filename v3.csv" "filename v4.csv" [6] "filename v5.csv" "filename v6.csv" "filename v7.csv" "filename v8.csv" "filename v9.csv" tail(basenames,1)`。相反,您需要删除除指定版本顺序的所有字符,转换为正确的格式,然后排序。以下是您使用整数版本执行此操作的示例。

filename v10.csv' appears in the second position and would not be picked up by simple methods such at
然而,这很笨重且容易出错。如果可能的话,我建议转换到数据库或版本控制,或两者兼而有之。