直接调用函数时禁止加载消息(不完全加载程序包)

时间:2018-11-26 18:45:50

标签: r

我想像this post那样禁止加载消息,除了我不加载整个程序包而是直接调用函数。

例如,调用Cleveland, OH的功能如下:

response.write("</br>" + " SHORT HAND " + array.records[0].graph.nodes[0].short_name + "</br>");  

结果消息:

{
  "records": [{
    "id": 451193,
    "flex_id": "FLEX-451193",
    "name": "PO#SW31",
    "transportation_mode": "ocean",
    "freight_type": "port_to_door",
    "incoterm": "FOB",
    "master_bill_number": null,
    "house_bill_number": "",
    "metric_units": true,
    "chargeable_volume": "65.0",
    "calculated_weight": "19000.0",
    "calculated_volume": "65.0",
    "departure_date": "2018-12-10T12:00:00.000+08:00",
    "arrival_date": "2019-01-02T12:00:00.000-05:00",
    "target_delivery_date": null,
    "status": "Seller's Location",
    "archived_at": null,
    "total_weight": "19000.0",
    "total_volume": "65.0",
    "chargeable_weight": "19000.0",
    "pieces": "740",
    "origin_pickup_date": null,
    "pickup_date": null,
    "delivery_date": null,
    "cargo_ready_date": "2018-12-07",
    "container_type": "high_cubed",
    "containers": [],
    "commercial_invoices": [],
    "graph": {
      "nodes": [{
        "id": 5851211,
        "type": "Port",
        "name": "Los Angeles, CA",
        "iata_code": null,
        "icao_code": null,
        "lat": "33.734048",
        "lng": "-118.257608",
        "port_name": "Los Angeles, CA",
        "port_code": "2704",
        "customs_district_code": 27,
        "country_code": "US",
        "timezone": "America/Los_Angeles",
        "short_name": "Los Angeles, CA",
        "city_state_country": "Los Angeles, CA, United States",
        "airport": false,
        "aliases": ["Los Angeles", "Los Angeles, CA", "San Pedro, CA", "LOS ANGELES (CALIFORNIA), UNITED STATES"],
        "city": "Los Angeles",
        "tags_list": ["port_of_unloading", "fmc_port_of_unloading"]
      }, {
        "address": "Choice Cabinet (Primary Warehouse)",
        "id": 5836273,
        "tags_list": ["destination_address"]
      }, {
        "address": "Yangming Industrial Park (Wang Old Factory)",
        "id": 5836272,
        "tags_list": ["origin_address"]
      }, {
        "id": 5836271,
        "type": "Port",
        "name": "Cleveland, OH",
        "iata_code": null,
        "icao_code": null,
        "lat": "41.416371",
        "lng": "-81.576069",
        "port_name": "Cleveland, OH",
        "port_code": "4101",
        "customs_district_code": 41,
        "country_code": "US",
        "timezone": "America/New_York",
        "short_name": "Cleveland, OH",
        "city_state_country": "Cleveland, OH, United States",
        "airport": false,
        "aliases": ["Cleveland", "CLEVELAND", "CLEVELAND, US", "CLEVELAND, OH"],
        "city": "Cleveland",
        "tags_list": ["customs_entry", "place_of_delivery"]
      }, {
        "id": 5836269,
        "type": "Port",
        "name": "Shanghai, China",
        "iata_code": null,
        "icao_code": null,
        "lat": "31.230418",
        "lng": "121.473701",
        "port_name": "Shanghai, China",
        "port_code": "57035",
        "customs_district_code": null,
        "country_code": "CN",
        "timezone": "Asia/Shanghai",
        "short_name": "Shanghai, China",
        "city_state_country": "Shanghai , China",
        "airport": false,
        "aliases": ["SHANGHAI (SHANGHAI), CHINA", "Shanghai"],
        "city": "Shanghai ",
        "tags_list": ["port_of_loading"]
      }],
      "legs": [{
        "origin_id": 5851211,
        "destination_id": 5836271,
        "transportation_mode": "rail",
        "freight_carrier_id": 2255,
        "tracking_number": null,
        "vessel_name": null,
        "vessel_imo": null,
        "scheduled_departure": "2018-12-25T12:00:00.000-08:00",
        "scheduled_arrival": "2019-01-02T12:00:00.000-05:00",
        "actual_departure": null,
        "actual_arrival": null
      }, {
        "origin_id": 5836269,
        "destination_id": 5851211,
        "transportation_mode": "ocean",
        "freight_carrier_id": 2255,
        "tracking_number": "075E",
        "vessel_name": "HANNOVER BRIDGE",
        "vessel_imo": "9302138",
        "scheduled_departure": "2018-12-10T12:00:00.000+08:00",
        "scheduled_arrival": "2018-12-24T12:00:00.000-08:00",
        "actual_departure": null,
        "actual_arrival": null
      }, {
        "origin_id": 5836271,
        "destination_id": 5836273,
        "transportation_mode": "truck",
        "freight_carrier_id": 2018,
        "tracking_number": null,
        "vessel_name": null,
        "vessel_imo": null,
        "scheduled_departure": null,
        "scheduled_arrival": null,
        "actual_departure": null,
        "actual_arrival": null
      }, {
        "origin_id": 5836272,
        "destination_id": 5836269,
        "transportation_mode": "truck"
      }]
    },
    "freight_cost": 0,
    "customs_cost": "125.0",
    "origin_address": "Yangming Industrial Park (Wang Old Factory), Shanghai Timber I/E, Xuanxing, Jiangsu, China",
    "destination_address": "Choice Cabinet (Primary Warehouse), Choice Cabinet, Bedford Heights, OH, United States"
  }]
}

如何防止此消息出现?到目前为止,我发现的唯一解决方案是按以下方式加载raster

f <- system.file("external/test.grd", package="raster")
r <- raster::raster(f)
p <- raster::rasterToPolygons(r, dissolve = TRUE)

但是当我从一个软件包中使用函数Loading required namespace: rgeos 时,我并不想完全加载rgeos

1 个答案:

答案 0 :(得分:0)

我曾经尝试过尝试过,但显然没有尝试过。这两个选项均有效:

p <- suppressMessages(raster::rasterToPolygons(r, dissolve = TRUE))
p <- suppressPackageStartupMessages(raster::rasterToPolygons(r, dissolve = TRUE))

我使用::(由Hadley here建议)显式调用该函数,但是您也可以通过将其导入到您的rgeos中来避免加载NAMESPACE消息。包。如果使用roxygen2,则意味着在函数顶部添加@import rgeos作为roxygen2注释。我想@importFrom rgeos fun也可以工作,但是我不知道rgeos正在使用哪个raster::rasterToPolygons函数。