从read.csv(file.choose())获取文件名(Get filename from read.csv(file.choose( )))
我想知道是否可以从read.csv调用中嵌入的file.choose()命令中提取文件名。 现在我分两步来做,但用户必须选择同一个文件两次,以便提取数据(csv)和文件名,以便在我运行的函数中使用。 我想这样做,所以用户只需要选择一次文件,然后我就可以同时使用数据和文件名。
以下是我正在处理的内容:
data <- read.csv(file.choose(), skip=1)) name <- basename(file.choose())
如果有帮助,我正在运行OS X,因为我认为file.choose()具有不同的行为,具体取决于操作系统。 提前致谢。
I'm wondering if it would be possible to draw out out the filename from a file.choose() command embedded within a read.csv call. Right now I'm doing this in two steps, but the user has to select the same file twice in order to extract both the data (csv) and the filename for use in a function I run. I want to make it so the user only has to select the file once, and then I can use both the data and the name of the file.
Here's what I'm working with:
data <- read.csv(file.choose(), skip=1)) name <- basename(file.choose())
I'm running OS X if that helps, since I think file.choose() has different behavior depending on the OS. Thanks in advance.
原文:https://stackoverflow.com/questions/9233471
最满意答案
在(引用)表
vulling
您需要为外键设置vulling
值。 但你没有。 你有三元组(vulling, put, spoor)
独特价值,这些价值并不代表对的唯一性(spoor, vulling)
。考虑
vulling ====================== vulling | put | spoor ---------------------- 1 | 0 | 0 1 | 1 | 0
这两排在三联体方面是
vulling
,而不是一对vulling
和vulling
。 最后,您应该在表定义中添加UNIQUE(vulling, spoor)
,或者使用helper-table管理多对多关系。或者你可以反转外键def:
ALTER TABLE vulling ADD FOREIGN KEY (spoor,vulling) REFERENCES put_25_vlak_1_spoor(spoor,vulling);
On (referenced) table
vulling
you need to have uniqe values for your foreign key. But you don't. You have unique values for triplet(vulling, put, spoor)
which not nessecerly mean uniqness of pair(spoor, vulling)
.Consider
vulling ====================== vulling | put | spoor ---------------------- 1 | 0 | 0 1 | 1 | 0
That two rows are uniqe in terms of triplet but not as a pair of
vulling
andspoor
. In the end you should either addUNIQUE(vulling, spoor)
to your table definition, or manage many-to-many relation using helper-table.Alternatively you may reverse te foreign key def:
ALTER TABLE vulling ADD FOREIGN KEY (spoor,vulling) REFERENCES put_25_vlak_1_spoor(spoor,vulling);
相关问答
更多-
一般来说,事前测试不是一个好主意,因为它要求您显式锁定表以防止其他客户端在测试和插入之间更改或插入数据。 显式锁定对并发性有害。 通过失败的插入自动递增的序列通常不是问题。 只是不要假设插入数据库的值是连续的。 数据库和obj-c是两个完全不同的东西。 让数据库检查问题,更容易向模式添加适当的约束,然后检查客户端程序中的所有内容。 默认是回滚到事务的开始。 但您可以使用保存点控制它并回滚到保存点。 但是,CTE是查询的一部分,并且当部分查询失败时,查询总是完全回滚。 但是,您可以通过将CTE拆分为创建临时表 ...
-
SQLite命令添加一个名为myconstraint的列,没有数据类型,列约束CHECK a != b (需要括号才有效)。 SQLite的ALTER TABLE无法添加表约束。 ( 替代方案更不便携。) The SQLite command adds a column named myconstraint, with no data type, and a column constraint CHECK a != b (which needs parentheses to be valid). SQLit ...
-
Postgresql约束(Postgresql constraint)[2023-05-11]
如果您发布错误消息,这将有所帮助。 但我想你只是错过了圆括号: ALTER TABLE my_table ADD CONSTRAINT my_fk FOREIGN KEY (my_field) REFERENCES my_foreign_table ON DELETE CASCADE; It would help if you posted the error message. But I think you are just missing the parenthesis: ALTER TABL ... -
您尝试链接到尚不存在的产品和kaart。 移动: INSERT INTO kaart_product VALUES (1,1); 下两行: INSERT INTO product VALUES ('studentenproduct',1); 那应该为你做的工作。 尝试搜索谷歌的forgein关键约束及其工作原理。 You try to link to a product and a kaart that doesn't exist yet. Move: INSERT INTO kaart_product ...
-
PostgreSQL引用错误(PostgreSQL referencing error)[2023-04-25]
t_property_landlord.landlord_id不是唯一列。 它需要是外键才能引用它。 有关如何声明一个的信息,请参阅此处: https : //www.postgresql.org/docs/8.1/static/ddl-constraints.html 您的t_property_landlord表应如下所示: create table if not exists t_property_landlord( landlord_id BIGSERIAL UNIQUE NOT NULL, ... -
也许你应该向导入工具生产者提出这个问题。 暂时禁用约束没有简单的方法; 你必须自己放弃并重新创建它们。 查看输出pg_dump --section=post-data应该会有所帮助,因为它包含了在末尾创建所有约束的命令。 Maybe you should raise this issue with the import tool producers. There is no simple way to temporarily disable constraints; you'd have to drop a ...
-
你宣布了这种关系: FOREIGN KEY(sectionNumber) REFERENCES Sections(sectionNumber) sectionnumber未声明为唯一。 您需要修复数据结构或使用主键。 You have this relationship declared: FOREIGN KEY(sectionNumber) REFERENCES Sections(sectionNumber) sectionnumber is not declared to be unique. Yo ...
-
要动态删除和重新创建外键约束,可以将其全部包装在函数中或使用DO命令: DO $body$ DECLARE _con text := ( SELECT quote_ident(conname) FROM pg_constraint WHERE conrelid = 'myschema.mytable'::regclass AND confrelid = 'myschema.myreftable'::regclass LIMIT 1 ...
-
在PostgreSQL 8.3中使用非null和唯一约束的增量字段(Increment field with not null and unique constraint in PostgreSQL 8.3)[2022-11-04]
另一个表,具有多个唯一索引: create table utest(id integer, position integer not null, unique(id, position)); test=# \d utest Table "public.utest" Column | Type | Modifiers ----------+---------+----------- id | integer | position | integer | not nu ... -
PostgreSQL约束错误(PostgreSQL constraint error)[2023-01-18]
在(引用)表vulling您需要为外键设置vulling值。 但你没有。 你有三元组(vulling, put, spoor)独特价值,这些价值并不代表对的唯一性(spoor, vulling) 。 考虑 vulling ====================== vulling | put | spoor ---------------------- 1 | 0 | 0 1 | 1 | 0 这两排在三联体方面是vulling ,而不是一对vulling和vulling ...