You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用rpubchem调用get.cid()从PubChem采数据报错,求排查

Hey there, let's figure out why you're hitting that error with rpubchem and your CID 46926545.

First, the error second argument must be a list is telling you that the get.cid() function is trying to combine data from PubChem, but the data structure it's getting back doesn't play nice with its internal code. Here's what's going on and how to fix it:

The Root Cause

The rpubchem package is pretty outdated—its last update was way back in 2015. PubChem's API has evolved since then, and some compound entries (like your CID 46926545) might return data in a format the package can't parse correctly. The function's attempt to bind data columns together with do.call(cbind) breaks because the input isn't a list like it expects.

Solution 1: Use an Actively Maintained Package (Best Bet)

Ditch rpubchem for webchem—it's kept up to date and handles PubChem requests smoothly. Here's how to use it for your CID:

# Install first if you haven't
install.packages("webchem")
library(webchem)

# Grab key properties for your compound
my_compound <- pc_get_compound(46926545, properties = c("MolecularFormula", "MolecularWeight", "IUPACName"))
print(my_compound)

This will give you a clean data frame with the info you need, no parsing errors.

Solution 2: Query PubChem's API Directly

If you want full control, use httr and jsonlite to call the API yourself. This avoids any package-specific bugs:

library(httr)
library(jsonlite)

# Make the API request
response <- GET("https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/46926545/property/MolecularFormula,MolecularWeight,IUPACName/JSON")

# Parse the JSON response
compound_data <- fromJSON(content(response, "text"))$PropertyTable$Properties
print(compound_data)

You can adjust the properties in the URL to get exactly what you need.

Why get.cid() Fails for This CID

Looking under the hood of rpubchem, the get.cid() function tries to mash together multiple property lists into a data frame. But for your CID, the data returned from PubChem doesn't fit the structure the package expects—maybe a missing field or a nested value that breaks the cbind call. Since the package isn't maintained anymore, this bug won't get fixed.

内容的提问来源于stack exchange,提问作者Sidd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:59:15